Solved Copy *.txt From Folders and Subfolders to One Folder

September 29, 2012 at 05:37:43
Specs: Windows XP and 7
Dear All

I have a problem to copy all files *.txt generated every days by systems, so I decided to wrote batch files. My Problem is :
How to copy files *.txt as today date modified from subfolders to one folder (another drive).

Example :
Source files *.txt in subfolders
D:\gemscol\key\voucher\normal (in folder normal there is many subfolders again that generates every day and in that subfolders have many *.txt generates every day too that I want to copy to destination path).
Destination path is C:\duplicate

After that, can we do otherwise? from c:\duplicate, the *.txt that generates as today move to subfolders D:\gemscol\key\voucher\normal (folders in folder normal) as subfolders creates today too (*.txt files generates today move to subfolders that generates today too)

If you dont mind and take the time to coding it.

Thanks before


See More: Copy *.txt From Folders and Subfolders to One Folder

Report •

#1
September 29, 2012 at 08:55:49
for /r "c:\bck" /d %%a in (.) do @copy /y "%%a\*.txt" C:\duplicate credits go to razor.

Report •

#2
September 29, 2012 at 09:03:19
Thanks for your reply, but it doesn't work :(

Report •

#3
September 29, 2012 at 20:12:36
✔ Best Answer
@echo off & setlocal enabledelayedexpansion
set arch=c:\duplicate
cd /d %arch%
set rev=%date:~-4%%date:~4,2%%date:~7,2%.bat
set dest=D:\gemscol\key\voucher\normal
:: this builds the "reverse-engine" batch based on date of the archive-run
cd /d %dest%>%rev%
for /f "tokens=*" %%a in ('dir /s /b *.txt') do (
:: build the reverse-engine batch
>> %rev% echo copy /y %arch%\%%~nxa %%a
:: now copy/move
copy /y %%a %arch%
)
::===== end

not tested. reverse-action ("restore") batch files stored as yyyymmdd.bat which are also stored in the archive directory ("duplicate").


Report •

Related Solutions

#4
September 30, 2012 at 08:46:30
Dear Nbrane,

Thanks for your time to respon and coding for me, but the command you give to me doesnt work. The respon from cmd went I insert pause to see the respons is

The system cannot find the path specified.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
The system cannot find the path specified.
The file cannot be copied onto itself.
0 file(s) copied.
Press any key to continue . . .

This restore batch file I want to use to make it back all *.txt file from c:\Duplicate to subfolders that create today (since we know the *.txt file in the c:\Duplicate have date modified today too).

The destination path of the subfolders is D:\gemscol\key\voucher\normal (in folder normal there is many subfolders again that generates every day. And like you writes Nbrane before, that subfolders exactly name with format yyyymmdd and that subfolders created automatically by system so we don't to create the subfolders again.

Thanks before, I'm still coding too, hope we can solve this


Report •

#5
September 30, 2012 at 11:04:08
Dear Nbrane,

I have debug this line command, the false is set rev

set rev=%date:~-4%%date:~4,2%%date:~7,2%.bat
set dest=D:\gemscol\key\voucher\normal
:: this builds the "reverse-engine" batch based on date of the archive-run
cd /d %dest%>%rev%


if my date format (we can see with type command echo.%date%) is dd/mm/yyyy, so the set rev must be :

set rev=%date:~-4%%date:~3,2%%date:~0,2% :: without.bat at the end of this line

Now I'm still debug this few line :

for /f "tokens=*" %%a in ('dir /s /b *.txt') do (
:: build the reverse-engine batch
>> %rev% echo copy /y %arch%\%%~nxa %%a
:: now copy/move
copy /y %%a %arch%
)

Thanks before.


Report •

#6
September 30, 2012 at 12:05:13
Dear Nbrane,

Thanks for your clue, now I get the correct command, debug from your command.

Thanks or your concern.


Report •

#7
September 30, 2012 at 17:15:22
Glad you got it working. I neglected to consider the date-format issue, so that's my bad. It looked like the rest of it should have worked, so i didn't bother to test, but I should have run a test (my other bad). At least we got there... good luck down-the-road.

Report •

Ask Question