Solved

Archiving Files

Posted on 2008-06-19
4
188 Views
Last Modified: 2010-04-16
I need to have the ability to archive files to a folder with a timestamp daily. I would first like to check to see if any files are int eh directory and if no files are present I need shut the program down. Hee is the code that I have thus far

SET TIMESTAMP=%DATE:~-4%.%DATE:~4,2%%DATE:~7,2%-%time:~0,2%%time:~3,2%
SET TargetDir=C:\Archive\Text_%TimeStamp%
md  %TargetDir%

move C:\Temp\*.txt %TargetDir%

0
Comment
Question by:earngreen
  • 2
4 Comments
 
LVL 38

Expert Comment

by:Shift-3
ID: 21822793
You could add lines like these.  If no .txt files are found then it will skip to the end of the script.


dir "C:\Temp\*.txt" > NUL 2>&1

if ERRORLEVEL==1 goto :eof

Open in new window

0
 
LVL 2

Expert Comment

by:krylosz
ID: 21822848
This will check if c:\temp is empty and if it is no will exit with errorlevel == 1

dir C:\Temp\*.* /b | find /v "O35cH70Ch" >nul && EXIT 1
0
 

Author Comment

by:earngreen
ID: 21823106
Shift-3

that works great. The secod problem that I am having is that the move will not work with the timestamp folder. I am not sure what the problem may be no error reported. When I take he timestamp function off it performs as normal.
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 21823284
Hmm, it works for me.

Try enclosing the paths in quotes as below.


@echo off

setlocal
 

SET TIMESTAMP=%DATE:~-4%.%DATE:~4,2%%DATE:~7,2%-%time:~0,2%%time:~3,2%

SET TargetDir=C:\Archive\Text_%TimeStamp%

md %TargetDir%
 

dir "C:\Temp\*.txt" > NUL 2>&1

if ERRORLEVEL==1 goto :eof
 

move "C:\Temp\*.txt" "%TargetDir%"

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now