Computing Staff
  • 2

Copy *.Txt From Folders And Subfolders To One Folder

  • 2

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

Share

1 Answer

  1. @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”).

    • 0