Solved

Archiving Files

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

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…
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 high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

707 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