0

I am learning C and am downloading a GitHub repository through code. This downloads the code to the current working directory (essentially where the C app is executed from). Is there a way to set the download directory?

Meaning always always have the file download to C:\Data\ProdData\

#include <stdlib.h>

int main(void)
{
  return system("git clone https://github.com/manleyManlious22/TestData");

}
Doctor Ford
  • 440
  • 1
  • 5
  • 17
  • Look at `chdir` to change the current working directory: https://www.gnu.org/software/libc/manual/html_node/Working-Directory.html – Joe Feb 10 '19 at 20:54
  • Holy smokes, I had no idea it was as easy as chdir. Knowing the command to look for saves plenty of time on google, lol – Doctor Ford Feb 10 '19 at 20:58

1 Answers1

1

You should just add it to your command:

#include <stdlib.h>

int main(void)
{
  return system("git clone https://github.com/manleyManlious22/TestData C:\\Data\\ProdData\\");
}

Also, I'm not on windows so I can't check the path, but it does work on linux.

With the system call, you are running a command as if you were in a terminal. Any command which works in your shell should work there.

Keldorn
  • 1,980
  • 15
  • 25