I have files in a folder structure on one network drive and need to copy them via batch to another folder structure on a separate network drive.
I have a batch script that copies them from the source to the destination but it only copies them into the top-level, not into the folders.
Ex:
SOURCE
newsletters
|-2016
|-2017
|-2018
DESTINATION
newsletters
|-2016
|-2017
|-2018
My script copies the files inside the SOURCE\newsletters\.. folders but only puts them into DESTINATION\newsletters, not inside the year folders:
#echo off
setlocal EnableDelayedExpansion
for /R %G IN (*.pdf) DO xcopy "%G" "DESTINATION\newsletters"
Figured it out with ROBOCOPY:
robocopy ./ DESTINATION\newsletters\ /E *.pdf
Related
my batch script
set "Sourcefolder=D:\PurgeScriptExecute\SourceFile"
set "Destfolder=D:\PurgeScriptExecute\DestFile"
set _NoOfDays=30
robocopy /S /MINAGE:%_NoOfDays% "%Sourcefolder%" "%Destfolder%" /E
echo File copied Successful^>^>%Sourcefolder%>>%Destfolder%
This works perfectly but only for files and not the folders inside the source directory .I don't understand why ??
Note
I don't have to move the files and folders . I need to copy them.
I'm trying a very simple batch script, but I must be missing something obvious.
The idea is to copy all files from a source folder and from its subfolders to one destination folder.
Both source and destination folder can be set manually.
The code below works, but it only copies the files of the source folder and not the files from the source subfolders. I guess it's because I use the src variable that it only looks into that folder, and not its subfolders.
set /p src=Enter source folder:
set /p dst=Enter destination folder:
md %dst%
for /r %%i in (%src%) do copy "%%i" %dst%
pause
I based it on the code below that I found on this forum. This one working, including copying the subfolders, but as I mentioned before, I can't define the (main) source folder, or I have to put the batch script in the folder I want to use as source folder:
for /r %%i in (*) do copy "%%i" %dst%
Thanks a lot!
for /r "%src%" %%i in (*) do copy "%%i" "%dst%"
Here's more detailed help for FOR /R
I have a folder with many subfolders inside them, the subfolders have random numbers/characters as their name, and they all do have an important file in them. But how do i copy all the files in the source folder and in the subfolders to one folder without copy the folders, in a batchfile?
I use Windows7
This should be all you need.
#echo off
for /r "d:\base\folder" %%a in (*) do copy "%%a" "c:\destination\folder"
I have many pictures in multiple directories and want to copy them to one folder, but my script is interrupted when a file with the same name already exists in the destination folder. I tried
for /R d:\dups %f in (*.jpg) do copy "%f" d:\pictures\.
What can i add to the code to append the name of the newer file before it's copied to the the destination folder? My source directory is "d:\dups" and my destination folder is "d:\pictures". thanks!
example:
#echo off
for /R "d:\dups" %%f in (*.jpg) do copy "%%f" "d:\pictures\New-%%f"
With a batch (.bat), I want to copy all mp3 files that are in 1 subdirectory of D:\TEMP
D:\TEMP\\(anyfolder)\\(anyfile.mp3)
to
E:\MYFOLDER\
I tried with xcopy but
I don't know how to tell "just recurse subfolders of D:\TEMP and not subsubfolders, subsubsubfolders, etc."
When using xcopy, folders are created in the destination (in order to replicate source's folder tree), I don't want this : files should be copied in just 1 single folder.
for command is your friend. Read help for and then try this in the command prompt
for /d %a in (*) do #echo %a
as you see, it follows all subfolders in the current directory.
thus,
for /d %a in (*) do #copy %a\*.mp3 e:\myfolder
will copy all your mp3 to the destination folder.