I wrote a simple program in C to create a file (filename comes from the first argument) in the current directory:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv){
FILE *fp;
if(argc != 2) exit(1);
fp = fopen(argv[1], "w");
if(fp == NULL) exit(1);
fclose(fp);
return 0;
}
I compile this with the Visual Studio C compiler, producing the executable createfile.exe, which I place on my Desktop and make hidden. I then added my Desktop to my Path environment variable.
My aim is to be able to open the Run window (using Win+R) and type createfile myfile.tex to create the file myfile.tex on my Desktop. When I execute the program in Command Prompt, the program works as intended, but if I type the command into the Run window, no file is created.
How can I modify the program or the environment to make this work as described above?
The file is probably written, but you do not control the working directory. You can use
SetCurrentDirectory, but under Windows, the desktop can be anywhere, and it is localized. It is named “Bureau” in my French Windows XP. That’s when SHGetSpecialFolderLocation comes in.Most people give up and instead of a program, they create this batch file :
It will create an empty file in the same directory as the batch file it self.