Sample batch file to create daily folder folder for archiving (and move file into the archive folder)

Everyday our server recieves several files in a inbound folder. The next daythe files are overwritten as they have the same names.

Is there a sample batch file where I can add to a daily 6am scheduled task to create a new daily folder by YYYYMMDD and move al the file into the new folder?

e.g. inbound folder c:\inbound\
location for archive folder - c:\archive\<YYYYMMDD>
Action - (1) create new daily folder YYYYMMDD in c:\archive\ , (2) move c:\inbound\*.* to c:\achive\YYYYMMDD

This batch file / scheuled task will run on a Windows 2008 server.

Who is Participating?
slemmesmiConnect With a Mentor Commented:
Dear sidarta,

since you will be running this on Windows Server 2008. I propose to use a PowerShell script and run this as a scheduled task.
The script could simply contain:
$InboundFiles = "C:\inbound\*.*"
$TodaysDate = get-date -uform "%Y%m%d"
$NewArchiveFolder = "C:\archive\$TodaysDate"
echo $NewArchiveFolder
md $NewArchiveFolder
mv $InboundFiles $NewArchiveFolder

Please let me know if you need any further assistance with this.

Kind regards,
finartConnect With a Mentor Commented:
you could create a file named mytask.cmd containing the following instructions:

FOR /F "usebackq tokens=2,3,4 delims=/ " %%A IN (`date /T`) DO SET X=%%C%%A%%B
echo %X%
mkdir c:\ARCHIVE\%X%
move c:\inbound\*.* to c:\achive\%X% /Y

then, plan a stask with the task scheduler that launches the mytask.cmd
jablonovoConnect With a Mentor Commented:
In windows there is a task scheduler.

1. Create your script.
2. add the script in task scheduler where you can give the details of when you want to task (script) to run. I suggest you use the task scheduler wizard. After the wizard is completed

Here is how to add a date to a folder 

all your command should be in a text file that you save with .cmd extension

hope this helps
slemmesmiConnect With a Mentor Commented:
Dear guys,

please beware that when you rely on the "date" command and delimiters, this is influenced by the "short date" format (regional setting) of the system.
The PowerShell script is not.

Kind regards,
sidartraAuthor Commented:
Siemmesmi, you are correct, the powershell script is not affected by the short date format. Thanks.
All Courses

From novice to tech pro — start learning today.