gpt4 book ai didi

command-line - Vista命令行上的递归文件复制和重命名

转载 作者:行者123 更新时间:2023-12-03 09:28:56 24 4
gpt4 key购买 nike

我正在尝试遍历我的音乐目录并将每个名为 folder.jpg 的文件复制到同一目录中名为 cover.jpg 的文件中。

我尝试了 this question 中的各种建议比如这样:

for /r %i in (folder.jpg) do copy %i cover.jpg

导致“系统找不到指定的文件。”

我该如何解决这个问题?

编辑

这就是我最终的结果:

for /r %i in (folder.jpg) do copy "%i" "%~picover.jpg"

最佳答案

试试这个:

for /f "usebackq delims==" %I in (`dir /b /s ^| findstr folder.jpg`) do copy "%I" "%~pIcover.jpg"

解码环:

usebackq :: run the command in the backquotes and use the output as the input for the loopdelims== :: use the equal sign as a delimeter. Really you could use any character that isn't valid in a file namedir /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 secondfindstr :: 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 \

我希望这会有所帮助!

关于command-line - Vista命令行上的递归文件复制和重命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/900578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com