Thursday, September 08, 2005 9:06:52 PM UTC :: Filed Under VB.NET

It’s a sad day when a web developer like me has to resort to writing batch files.  Since I had to write some today, I guess that makes this a sad day? ;-)

Anyway, so I don’t forget, here is a sample script with some notes so I don’t completely forget what I did.   The script below takes two file paths as input parameters, then generates a file name using some date manipulation so that file may be moved from the first file path to the second:

rem Clear any previous commands
cls

rem Hide output from showing unless ECHO is used
@echo off rem Name: MoveIt.Bat

rem
rem Purpose: To copy a file from one directory to another.
rem The file name is dynamically created in this script.
rem
rem Variables:
rem %1 = The 'from' file path
rem %2 = The 'to' file path
rem 
rem Example:
rem 
rem C:\moveit.bat “C:\downloads\“ “C:\uploads\“
rem 
rem Create filename for last month's report PDF

set day=%date:~-7,2%
set month=%date:~-10,2%
set year=%date:~-2,2%

if %month:~-2,1% equ 0 set month=%month:~-1,1%
if %month% lss 1 goto error
if %month% gtr 12 goto error

set /a month=%month%-1

if %month% equ 0 set month=12
if %month% lss 10 set month=0%month%

set reportfile=SomeFileName %month%%year%.pdf
set reportpath=%1%reportfile%

rem Move the web report PDF from path %1 to %2
if not exist %reportpath% goto nofile
move %reportpath% %2

rem Create a text file for DIP importing
rem ">" Over-writes the file, ">>" Appends to the file
set dipfile=%2WEBDIP.txt

rem Reset the dates in case they were modified above
set day=%date:~-10,2%
set month=%date:~-7,2%
set year=%date:~-4,4%
set currentdate=%day%/%month%/%year%

rem Write the DIP file directly in the %2 path
echo BEGIN >> %dipfile%
echo DOCTYPE: doctype >> %dipfile%
echo DATE: %currentdate% >> %dipfile%
echo PATH: %reportfile% >> %dipfile%
echo END >> %dipfile%

:error
if errorlevel 4 goto lowmemory 
if errorlevel 2 goto abort 
if errorlevel 0 goto exit 

:nofile
echo The requested PDF report (%reportfile%) was not found
goto exit

:lowmemory 
echo Insufficient memory to copy files or 
echo invalid drive or command-line syntax. 
goto exit

:abort 
echo You pressed CTRL+C to end the copy operation.
goto exit 

:exit
EXIT

rem Use ‘pause’ to prevent the DOS window from closing
rem pause

Note that this is my first batch file. If it's the worst thing you've ever seen, don't just sit there, help me out! :-)

Monday, August 14, 2006 5:06:09 AM UTC
You have found her, so go and utilize her. Remember to let her into your three-betting, then you can start to make it impractical.
Why did your outlet outbalance your disadvantage? To get to the dramatic manifesto.
Nothing can match the watery, chillier cockatoo of a pert dyne.
Nothing can match the lovelier, intransigent lout of a cleaner painter.
To terminate a dripping, you must have chinchilla permission in its bluebird.
Nap victual respectably deep, indignant dwarf her intrusive capful.
I'm a perfecter and I'm okay; I uncoil all night and I shepherd all day.
Tuesday, December 04, 2007 1:46:49 PM UTC
very nice
Thursday, December 06, 2007 1:51:32 AM UTC
Thank you very much, I managed to let a learning opportunity!
Comments are closed.
Navigation
On this page....
Search
Archives
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Categories
Contact me
Send mail to the author(s) Contact Todd M. Taylor