1

I am trying to copy all .txt files that I have scattered throughout several subdirectories of one main directory into another directory using a batch file. I have research this site and found lots of answers at this link: batch file Copy files with certain extensions from multiple directories into one directory. Like the code below from Jay:

set dSource=C:\Main directory\sub directory
set dTarget=D:\Documents
set fType=*.doc
for /f "delims=" %%f in ('dir /a-d /b /s "%dSource%\%fType%"') do (
copy /V "%%f" "%dTarget%\" 2>nul

)

My question is how to modify this code or other codes on this link to batch copy the files with time stamps, like I only want to copy .txt files created from Jan 1, 2012 to Nov 1, 2012.

Community
  • 1
  • 1

1 Answers1

1

My suggestion for finding and moving *.txt files in a directory tree of a drive, or the entire drive, or even multiple drives with last modification date in a definite time period is:

  1. Start Windows Explorer.
  2. Click on button Search.
  3. Open advanced search options for finding files and folders.
  4. Select/enter to search for files by last modification date.
  5. Enter the two dates to specify time period or select the time period.
  6. Run the search.
  7. Select all found files in search result, for example with Ctrl+A.
  8. Press Ctrl+X to mark the found files for being cut (moved).
  9. Open the folder into which the files should be moved.
  10. Press Ctrl+V to paste the files (move them).

That's it.

Nobody needs to code a batch job for this task if this find + move files job should not be done periodically using a scheduling task.

The exact steps for doing such an advanced find for files in a definite time period with Windows Explorer depends on version of Windows. See for example the computer tips

And of course there are many freeware and shareware tools which support also finding files according to various search criterias like last modification date within a specified time period and move them.

Well, that does not really answer the question as it does not contain the batch code for doing the job. So I answer this question with another question:

Why thinking about coding a batch file for such a task hard to adapt for varying dates if dozens of GUI applications including Windows Explorer exist doing the same by simple user input with no need on coding skills and therefore very easy to use, and the find + move must be done only once or from time to time with changed criterias?

Mofi
  • 46,139
  • 17
  • 80
  • 143