How to copy files using Windows package?

I have a directory with several subdirectories with files.
How to copy all files to subdirectories in a new location?

Edit: I don't want to copy directories, just files ...

Since this is still on XP, I chose the following solution:

for /D %S IN ("src\*.*") DO @COPY "%S\" "dest\" 

Thanks!

+4
source share
6 answers

Ok With your editing that says you don't need a directory structure, I think you will want to use something like this:

 for /F "usebackq" %s IN (`DIR /B /S /AD SrcDir`) DO @( XCOPY %s DestDir\%~nxs ) 
+6
source

The Xcopy team should help here.

 XCOPY /E SrcDir\*.* DestDir\ 

Or, if you do not want any files in SrcDir, only subdirectories, you can use XCOPY in combination with the FOR command:

 FOR /D %s IN (SrcDir\*) DO @XCOPY /E %s DestDir\%~ns\ 
+3
source

robocopy "c:\source" "c:\destination" /E

+2
source

If I understand correctly, you have a large directory tree, and you want all the files inside it to be in the same directory. If this is correct, then I can do it in two lines:

 dir /s /b "yourSourceDirectoryTreeHere" > filelist.txt for /f %f in (filelist.txt) do @copy %f "yourDestinationDirHere" 

In the batch file compared to the command line, change% f to %% f

+1
source

If you want to keep the same folder structure at the other end, it sounds as simple as XCOPY

xcopy c: \ old \ *. * d: \ new \ / s

Use / e instead of / s if you also want to copy empty directories.

0
source
  for /D %S IN ("src\*.*") DO @COPY "%S\" "dest\" 
0
source

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


All Articles