Solved

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

Posted on 2010-08-30
5
1,057 Views
Last Modified: 2012-06-27
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.

Thanks.
Joo
0
Comment
Question by:sidartra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Accepted Solution

by:
slemmesmi earned 250 total points
ID: 33564723
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,
Soren
0
 
LVL 1

Assisted Solution

by:finart
finart earned 125 total points
ID: 33564777
Hello,
you could create a file named mytask.cmd containing the following instructions:

@ECHO OFF
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
0
 

Assisted Solution

by:jablonovo
jablonovo earned 125 total points
ID: 33564856
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

http://dev-notes.com/code.php?q=49 

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

hope this helps
0
 
LVL 11

Assisted Solution

by:slemmesmi
slemmesmi earned 250 total points
ID: 33564940
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,
Soren
0
 

Author Closing Comment

by:sidartra
ID: 33564960
Siemmesmi, you are correct, the powershell script is not affected by the short date format. Thanks.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question