?
Solved

Archiving Files

Posted on 2008-06-19
4
Medium Priority
?
196 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
[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
  • 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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 …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

771 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