Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
need help with a dos batch script.
Name: cnpdm Date: June 18, 2009 at 11:58:56 Pacific OS: Windows XP Subcategory: Batch
Comment:
Hi members, I am trying to convert a unix shell script to dos. It needs to delete all .test files in a directory and write to log file that the command was successful. When there are no files, it should write "no files available" to the logfile.
I have this right now:
SET DIR=C: SET LOGFILE="C:\test.log" SET DATE=%mm%%dd%%yyyy% echo %DATE% >> %LOGFILE%
echo Deleting old .test files > %LOGFILE% echo "" >> %LOGFILE del %DIR%\*.test echo Deleted old .test files > %LOGFILE%
I need to add the if else condition. i.e when there are no files available, it should write the same. Any help will be appreciated.
@echo off
set drive=C:
set logfile=C:\test.log
echo.%date% > %logfile%
echo.Deleting old .test files >> %logfile%
echo.>> %logfile%
if exist %drive%\*.test (
del %drive%\*.test
echo.Deleted old .test filesfrom %drive%\*.test >> %logfile%
) else (
echo. No files available >> %logfile%
)
:: End_Of_Batch
First of all use lowercase to improve readibility. Then use the %date% system variable to be NEVER modified. More if you want to delete the *.test files in the root directory AND all the subdirs add the /S switch at the end of the DEL command.
By the way this is NT batch nothing to do with DOS (that does not exist in XP).
Summary: I need help with a DOS Batch File. I have added my batch file to a Win98 Boot Floppy. The Batch file includes a Menu. One of the Menu Choices is for copying the WinXP I386 Folder etc. to a C:\I386, Fo...
Summary: Hi, I need a help in MS DOS batch script. Can I call an Internet session in a batch mode in DOS script? Following example explains my problem. @echo off iexplore www.mytestphp.com^&myparam.php re...
Summary: Need help with a C++ program? But anyone you ask doesn't have the slightest idea what your talking about, let alone doing? Then visit http://www.subduck.com for the greatest C++ experience you'll ever...