涉及在 C 代码中二次使用 cd.. 的错误
Error involving secondary use of cd.. in C code
strcpy(strng, "cd.. ");
strcat(strng, "& copy %cd%\bin\");
strcat(strng, file);
strcat(strng, " %cd%\txt");
system( strng );
您好,我一直在 windows 中处理 C 的文件处理,不幸的是,我 运行 遇到了这个奇怪的泡菜。虽然我的大部分代码都可以正常工作,包括我之前 运行 遇到的问题,但“cd..”似乎没有正确转到父目录。有没有关于为什么 [或快速和类似的修复] 的说法?
在程序之前,它在这一行短代码中工作:
if (numLog > 8) {
system("cd.. & cd txt & del *.txt");
return errinit(); };
您的有效字符串是
cd..& copy %cd%\bin\file %cd%\txt
批处理解析整行,然后执行它,因此 %cd%
在 执行 cd ..
之前被计算为其值 。
copy %cd%\..\bin\file %cd%\..\txt
应该按照您的意愿行事。
strcpy(strng, "cd.. ");
strcat(strng, "& copy %cd%\bin\");
strcat(strng, file);
strcat(strng, " %cd%\txt");
system( strng );
您好,我一直在 windows 中处理 C 的文件处理,不幸的是,我 运行 遇到了这个奇怪的泡菜。虽然我的大部分代码都可以正常工作,包括我之前 运行 遇到的问题,但“cd..”似乎没有正确转到父目录。有没有关于为什么 [或快速和类似的修复] 的说法?
在程序之前,它在这一行短代码中工作:
if (numLog > 8) {
system("cd.. & cd txt & del *.txt");
return errinit(); };
您的有效字符串是
cd..& copy %cd%\bin\file %cd%\txt
批处理解析整行,然后执行它,因此 %cd%
在 执行 cd ..
之前被计算为其值 。
copy %cd%\..\bin\file %cd%\..\txt
应该按照您的意愿行事。