Recursive file copy and rename at Vista command line

I am trying to overwrite my music directory and copy each file named folder.jpg to a file in the same directory as cover.jpg.

I tried suggestion options in this question , for example:

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

Result: "The system cannot find the specified file."

How can I solve this problem?

Edit

Here is what I ended up with:

for /r %i in (folder.jpg) do copy "%i" "%~picover.jpg"
+3
source share
5 answers

Try the following:

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

Decoder Ring:

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 \

, !

+5

, , folder.jpg, ?

mymusic folder.jpg, .;)

:

, % i

+1

.

The variable% I will contain the full path to the file, which may contain spaces. Try using:

for /r %i in (folder.jpg) do copy "%i" cover.jpg
+1
source

PowerShell should replace CMD. It is inevitable and righteous. And it's my job to help him ...

gci -r . folder.jpg | % { copy $_.FullName ([IO.Path]::Combine( $_.Directory.FullName, "cover.jpg" )) }
+1
source

You can just use xcopy with the / s flag ...

EDIT: My bad - did not read the question correctly. Xcopy with / s will help when copying files to a fixed destination.

0
source

Source: https://habr.com/ru/post/1708926/


All Articles