Click here to Skip to main content
15,888,064 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to move files from a folder to another folder as a batch file based on a date span using Dos command.There will be a from date and to date specified and based on it files must move accordingly. The sub folders must be created dynamically and files according to the date condition must move with in the destination folde .

What I have tried:

I am able to entire folder as such to another specified based on modified date with below command.
forfiles /P "E:\Alex\FTS_DOS\FileStore\REP" /M *.DMP /D +0 /C "cmd /c copy @path E:\Alex\FTS_DOS\Dest_FileStore\REP"


But I need the move the files based on a date specified and create subfolders if any dynamically.
Posted
Updated 13-Sep-17 21:04pm
v3
Comments
OriginalGriff 14-Sep-17 2:19am    
And?
What have you tried?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.

1 solution

First thing is to look at how to work with files and dates - research time... This batch file get file date - Google Search[^] has a number of solutions.

This one sticks out: windows - How to get the date from a file in a bat file? - Stack Overflow[^] and down the bottom of that page is this: Delete files older than - Windows CMD - SS64.com[^]

Now you have a method to do the date test to complete your batch file.
 
Share this answer
 
Comments
[no name] 19-Sep-17 1:06am    
I want to set validation to archive files greater than 60 days in a bat file command.
I want to show a validation message if some or entire files not lesser than 60 days are archived
Below script not working based on validation
Hide Copy Code
@ECHO OFF
setlocal enabledelayedexpansion
set SOURCE="E:\FTS_NBF\FILESTORE\CAD"
SET DEST="E:\FTS_NBF\Dest_FILESTORE\CAD"
set /a days=60

echo %DEST% %DEST%


IF NOT EXIST %DEST% mkdir %DEST%

IF EXISTS (File Date >60)

forfiles /P %SOURCE%\ /M *.* /D -%days% /C "cmd /c move @path %DEST%\"

ELSE

echo It is not recommended to Archive Files older than 60 days........................

PAUSE
Graeme_Grant 19-Sep-17 1:28am    
Please don't post code in replies - you have posted over 40 questions, so you should know this already. As mentioned in the repost that you deleted:

Please update the question with clear and concise details, sample code, any error messages (including inner exception details), etc, by clicking on the Improve question widget.
[no name] 19-Sep-17 4:54am    
I got the solution for the same by setting Archival Time Span and checking it reading from a file and if not right validate message will be echoed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900