Copy file to all batch file folders?

I need a copy of credits.jpg from C:\Users\meotimdihia\Desktop\credits.jpg to D:\Software\destinationfolder and all subfolders I read a lot and I write

 /R "D:\Software\destinationfolder" %%I IN (.) DO COPY "C:\Users\meotimdihia\Desktop\credits.jpg" "%%I\credits.jpg" 

then I save saveall.bat file, but I run it, it doesn't work at all. help me write 1 bat

+4
source share
3 answers

Try:

 for /r "D:\Software\destinationfolder" %i in (.) do @copy "C:\Users\meotimdihia\Desktop\credits.jpg" "%i" 

Of course, if it goes into the batch file, double '%'.

+8
source

If you can use it: here is the PowerShell solution (PowerShell is integrated in Windows 7 and is available with XP and above):

 $file = "C:\...\yourfile.txt" $dir = "C:\...\YourFolder" #Store in sub directories dir $dir -recurse | % {copy $file -destination $_.FullName} #Store in the directory copy $file -destination $dir 

I'm sure the last line can be integrated into dir ... but I'm not sure how (I don't use PowerShell very often).

+1
source

This was the first Google search for batch file copy file to all subfolders .

Here is a way with xcopy . There is also Robocopy, but that would be too powerful for a simple task like this. (I used this to backup the entire drive because it can use multithreading)


But let's focus on xcopy .

This example is for saving to a file with the extension .bat . Just drop the extra % where there are two if they run directly on the command line.

 cd "D:\Software\destinationfolder" for /r /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K 
  • cd "D:\Software\destinationfolder" change the directory to the folder where you want to copy the file. Wrap this in quotation marks if the path has spaces.
  • for loop - see help here . Or type for/? on the command line.
  • /r - iterate over files (recurse subfolders)
  • /d - loop through several folders
  • %%I - %%parameter : replaceable parameter
  • xcopy - Type xcopy/? on the command line for a lot of help. You may need to press Enter to read all the help on this.
  • C:\temp\file.ext - the file you want to copy
  • "%%~fsI" - extends %%I to the full path with only short names
  • /H - Copy files with hidden and system file attributes. By default, xcopy does not copy hidden or system files
  • /K - copies files and saves the read-only attribute in the destination files, if present in the source files. By default, xcopy removes the read-only attribute.

The last two options are just examples if you are having problems with any read-only files and they preserve the most important file properties.

There are many xcopy options here

xcopy examples here


Just for completeness. In this example below, the same file will be copied to each folder in the current directory, not any subfolders. Just the /r option is removed so that it behaves like this.

 for /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K 
0
source

All Articles