Solved

Archiving Files

Posted on 2008-06-19
4
187 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

9 Experts available now in Live!

Get 1:1 Help Now