Wildcard search for directory... not file

July 21, 2009 at 12:32:12
Specs: Windows XP
Im new to this whole batch file thing but basically this is what im trying to accomplish. We have two servers that mirror each other - a development box which is X: and the actual live site, which is Y: I work with a team of web developers and when someone is done with a file (usually on the X: but not always) they will throw a ".old" on the end of it so everyone knows its not in use. So far ive gotten the script to scan both X: & Y: drives for ".old" files and then copy them to an archive while deleting the original off the server. My problem is this: if someone decides to give a folder (not an actual file but a "directory") the ".old" suffix my batch file wont recognize it. As i am new to the whole batch thing i am really at a loss as of how to make this happen. Thanks in advance for your help.


@echo off
:DATE
FOR /F "tokens=1-4 delims=/ " %%I IN ('DATE /t') DO SET mydate=%%J%%K%%L

:------------------------------------------------
:Copy Files on the X: Drive to Archive and Delete
:------------------------------------------------

echo Scanning X:\INTL0 directory for .old files...
if exist "X:\To Archive\ArchiveOf.oldFiles\%mydate%Archive\" GOTO errorX

xcopy "X:\INTL0\*.old" "X:\To Archive\ArchiveOf.oldFiles\%mydate%Archive" /S /I /C > "X:\To Archive\ArchiveOf.oldFiles\%mydate%ArchiveList.txt"
if not exist "X:\To Archive\ArchiveOf.oldFiles\%mydate%Archive" GOTO NoFIlesErrorX
echo Files successfully copied from X:\INTL0!
echo Removing .old files from X:\INTL0 directory . . .
ERASE /S /F X:\INTL0\*.old
GOTO middle

:NoFilesErrorX
echo ........................................
echo There are no .old files on the X: drive at this time:
echo ........................................
GOTO middle

:errorX
echo ..............................................
echo Backup has been ran today.
echo See the log @ X:\To Archive\ArchiveOf.oldFiles\%mydate%ArchiveList.txt
echo ..............................................

:middle

:------------------------------------------------
:Copy Files on the Y: Drive to Archive and Delete
:------------------------------------------------

echo Scanning Y:\INTL0 directory for .old files...
if exist "Y:\To Archive\ArchiveOf.oldFiles\%mydate%Archive\" GOTO errorY

xcopy "Y:\INTL0\*.old" "Y:\To Archive\ArchiveOf.oldFiles\%mydate%Archive" /S /I /C > "Y:\To Archive\ArchiveOf.oldFiles\%mydate%ArchiveList.txt"
if not exist "Y:\To Archive\ArchiveOf.oldFiles\%mydate%Archive" GOTO NoFIlesErrorY
echo Files successfully copied from Y:\INTL0!
echo Removing .old files from Y:\INTL0 directory . . .
ERASE /S /F Y:\INTL0\*.old
GOTO end

:NoFilesErrorY
echo ........................................
echo There are no .old files on the Y: drive at this time:
echo ........................................
GOTO end

:errorY
echo ..............................................
echo Backup has been ran today.
echo See the log @ Y:\To Archive\ArchiveOf.oldFiles\%mydate%ArchiveList.txt
echo ..............................................

:end


See More: Wildcard search for directory... not file

Report •


#1
July 21, 2009 at 15:04:15
use the /s or /e switch on xcopy to copy subdirectories. This way dir1.old will be copied

You will need to add a line to rd *.old to remove it after being copied


Report •

#2
July 22, 2009 at 05:29:43
When I use the /e switch it copies all the folders in the entire INT0 directory but none of the files. Also, just to note the lines that start with: xcopy "X:\INTL0\*.old" don't actually break until: %mydate%ArchiveList.txt". I just wanted to make that clear because its getting cut in half on the web page. Thanks again for your help

Report •

Related Solutions


Ask Question