【发布时间】:2023-03-27 12:05:01
【问题描述】:
@echo off
REM - Check to see if there are any non-school related files on the system (mp3, jpg, png, exe)
REM - And print them out #bigbrother1984
cd G:\Assign2\
FOR /F "tokens=*" %%G IN ('dir /s /b "G:\Assign2\*.mp3"') DO echo %%G >> Found_MusicFiles.txt
FOR /F "tokens=*" %%G IN ('dir /s /b "G:\Assign2\*.JPG"') DO echo %%G >> Found_ImageFiles.txt
FOR /F "tokens=*" %%G IN ('dir /s /b "G:\Assign2\*.PNG"') DO echo %%G >> Found_ImageFiles.txt
FOR /F "tokens=*" %%G IN ('dir /s /b "G:\Assign2\*.exe"') DO echo %%G >> Found_GamesFiles.txt
例如,这会在 Assign2 下找到 .mp3、jpg、png、exe 文件,并打印出它找到的结果。 但它会像这样打印出来 G:\Assign2\blah\blah\blah\blah\blah\Game.exe
我希望它打印出 \blah\game.exe 之类的东西
有什么想法吗?我尝试使用 %~nI,但我不知道如何使用它并且是批处理新手。
【问题讨论】:
-
你想要相对路径?
-
或者你想在你的for循环中使用
%%~nG? -
以“C:\USers\...”开头的示例输出与以“G:\Assign2\...”开头的脚本位置不匹配
标签: batch-file for-loop cmd dir