Ken*_*nny 3 recursion command-line for-loop copy windows-vista
我正试图通过我的音乐目录递归并将名为folder.jpg的每个文件复制到名为cover.jpg的同一目录中的文件中.
我在这个问题中尝试了各种建议,例如:
for /r %i in (folder.jpg) do copy %i cover.jpg
Run Code Online (Sandbox Code Playgroud)
导致"系统找不到指定的文件".
我怎么解决这个问题?
编辑
这就是我最终的目标:
for /r %i in (folder.jpg) do copy "%i" "%~picover.jpg"
Run Code Online (Sandbox Code Playgroud)
试试这个:
for /f "usebackq delims==" %I in (`dir /b /s ^| findstr folder.jpg`) do copy "%I" "%~pIcover.jpg"
Run Code Online (Sandbox Code Playgroud)
解码器环:
usebackq :: run the command in the backquotes and use the output as the input for the loop delims== :: use the equal sign as a delimeter. Really you could use any character that isn't valid in a file name dir /b /s :: do a recursive directory listing only outputting the bare file names ^| :: ^ escapes the pipe character, the pipe - well pipes the output from the first command to the second findstr :: searches the input for matching lines, and only outputs them %~pI :: the tilde p instructs the variable expansion to only output the path rather than full file name + path. Note, this includes a trailing \
我希望这有帮助!