VC++当前目录下

来源:百度知道 编辑:UC知道 时间:2024/06/05 11:36:40
我想当开 在我程序下当前目录 Bat文件架里的程序 需要怎么填写绝对路径 是否要用API函数?

不必填写绝对路径,可以用相对路径 “Bat\filename.exe”就可以了。

如果想保险起见,楼主可以用 GetModuleFileName 获得当前的文件所在的路径(含文件名),或者用 GetCurrentDirectory 获得当前路径,再操作字符串获得路径(不含文件名的),最后挂靠相对路径:bat\filename.exe。

通过GetCurrentDirectory 得到当前目录,然后在拼一下Bat目录就可以了。

TCHAR Buffer[BUFSIZE];
GetCurrentDirectory(BUFSIZE, Buffer);

strcat(Buffer, "\\Bat\\file.exe");