Batch script - move parent directory and subdirectory

1

How do I create a . bat to move all files in specific or better only those with .txt extension of one directory and all its subdirectories to another folder.

    
asked by anonymous 27.03.2016 / 08:26

1 answer

2

As I'm not sure I understand correctly, then we have 2 ways to solve your problem.

The form below will copy all files with the extension and subfolders to the destination and will create the same folders where the files with the extension were:

Solução 1

xcopy c:\*.txt d:\textos /sy
  

/ s will make it "recursive"
  / y asks if you want to replace.

Solução 2
For each file in the directory c:\ and subdirectories /R that correspond to the default ( .*txt ) will put the file name in the variable %%f , then for each file to the destination d:\textos , that is, all .*txt files that find does not matter the subfolder, will all go to d:\textos , if there is a repeated name to replace.

for /R c:\ %%f in (*.txt) do copy %%f d:\textos
  

/ R to go through subdirectories.

    
18.05.2016 / 21:25