Solved

Archiving Files

Posted on 2008-06-19
4
189 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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