Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 输出子文件夹中的所有文件:绝对文件路径_Windows_Batch File - Fatal编程技术网

Windows 输出子文件夹中的所有文件:绝对文件路径

Windows 输出子文件夹中的所有文件:绝对文件路径,windows,batch-file,Windows,Batch File,我试图列出子目录中所有文件的绝对路径。我能够找到并输出该子目录中的所有文件,但我输出的文件路径不正确,即缺少一个文件夹 我的文件夹结构: root: myBatchFile.bat SearchFolder: testfile1.txt testfile1.txt 当我输出文件夹“SearchFolder”中所有文件的文件路径时,它们缺少SearchFolder 批处理文件输出: C:/user/me/root/testfile1.txt C:/

我试图列出子目录中所有文件的绝对路径。我能够找到并输出该子目录中的所有文件,但我输出的文件路径不正确,即缺少一个文件夹

我的文件夹结构:

root:
    myBatchFile.bat
    SearchFolder:
        testfile1.txt
        testfile1.txt
当我输出文件夹“SearchFolder”中所有文件的文件路径时,它们缺少SearchFolder

批处理文件输出:

C:/user/me/root/testfile1.txt
C:/user/me/root/testfile2.txt
输出应为:

C:/user/me/root/SearchFolder/testfile1.txt
C:/user/me/root/SearchFolder/testfile2.txt
如何使批处理文件代码输出“SearchFolder”中文件的绝对路径?

REM // For all files in the folder 'SearchFolder': Compile them
for /r %%i in ("SearchFolder/*.txt") do echo %%i

这将适用于单个文件夹。对于命令行版本,将%%a减少到%a

for %%a in ("d:\abc\*.txt") do echo "%%a"

这不会在“根目录”中的所有子目录中搜索,而不仅仅是在“SearchFolder”中搜索吗?是的。您需要搜索的目录是否始终相同?我已编辑了我的答案。这将只搜索特定的SearchFolder目录。
for %%a in ("d:\abc\*.txt") do echo "%%a"
REM // For all files in the folder 'SearchFolder': Compile them
for %%i in ("SearchFolder/*.txt") do echo %%~Fi