Computing.Net > Forums > Programming > need help with a dos batch script.

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.

Reply to Message Icon

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.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 18, 2009 at 13:19:38 Pacific
Reply:

@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).


0
Reply to Message Icon

Related Posts

See More


Debuging a Struct Batch file to find ip and...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: need help with a dos batch script.

DOS Batch File Commands www.computing.net/answers/programming/dos-batch-file-commands/14637.html

MS Dos batch Script Help www.computing.net/answers/programming/ms-dos-batch-script-help/14592.html

Need help with C++? www.computing.net/answers/programming/need-help-with-c/4642.html