How to copy files from sub-folders in bulk (Windows)

How to copy files from sub-folders in bulk (Windows)

Hi there! Many a time, we get data from clients in a nested folder structure like the below:

No alt text provided for this image

and we need to have all the files or a specific type of files (for example all the Excel files) in subfolders copied over to one single folder. This requirement could be to have all the required files in one place so they are accessible quickly, without going into each subfolder separately, or to run any kind of automation process to extract data from all the files.

To achieve this requirement, the apparent way would be to go into each subfolder, copy the required files and paste them to the destination folder. This method is totally manual, cumbersome and wastage of time for the person doing it. A more automated and quick method to achieve the desired result is:

Copy the address of the parent folder from the address bar in Windows Explorer

No alt text provided for this image

Press Windows+R button and type 'cmd', a Command prompt window will open for you.

Type the following command and press Enter:

cd /d \path\to\your\source\folder\copied\above        

It should look something like this:

No alt text provided for this image

Once the above command is successful, if you want to copy all the files from the subfolders, you can type the following command (please ensure to include the quotation marks and that the destination folder is not inside the parent folder i.e. our source folder):

for /r %d in (*) do copy "%d" "\path\to\destination\folder"        

But what if you only want to copy a specific type of file from the subfolder, say only the Excel spreadsheet files? You can use the below command to achieve the same (replace .xlsx with whatever file format you want to copy):

for /r %d in (*.xlsx) do copy "%d" "D:\Test\Parent Folder_1"        

The command prompt window will show you the status of the files being copied and also the errors if any.

This only replaces the destination file over and over with each file it copies and prompts you each time. we don't want to replace we want to append or rather merge all *.txt or *.log that exist in the subfolders of the root directory. neither copy nor xcopy will do this despite the million articles around the net. Copoy only supports the root directly and xcopy is its on weird creature but too does not hand it. I have 15 logs in 15 subdirectories within the root directory, so 15 folders inside another folder. Inside each folder is a log file. I want to merge them all into one, just like the Copy command does but it has to pull from those 15 subdirectories within the root folder i am running the command from,

回复

要查看或添加评论,请登录

Vishal Sahjani的更多文章

社区洞察

其他会员也浏览了