Computing Staff
  • 12

Write DEL 0% To Other Batch To Delete Itself

  • 12

Hi.

I created c:\x.bat for testing purposes with following lines:

echo start c:\monday.html >> c:\test.bat
echo del 0% >> c:\test.bat

but when opening test.bat second line is
del “C:\x.bat”
not
del 0%

what’s wrong with the syntax?

thanks

Share

3 Answers

  1. Here you go much simpler…
    @echo off
    cls
    color 04

    Set Day=%Date:~-7,2%
    Set Month=%Date:~-10,2%
    Set Year=%Date:~-4,4%
    Set TodaysDate=%Year%-%Day%-%Month%
    Set LogPath=W:\TTT\
    Set LogFileExt=.log
    Set LogFileName=ALFA
    Set MyLogFile=%LogPath%%TodaysDate%_%LogFileName%%LogFileExt%

    NET USE P: /DELETE /Y
    NET USE P: \\Ser5\public\TTT\1\mnt\disk_u\HOME

    if exist “P:\c_data.DA1″ (
    Call copyfile
    )else(
    echo File Does not exist. >> %MyLogFile%
    )
    goto :EOF

    :copyfile
    move /Y T:\HOME\c_data.DA1 T:\HOME\copy\
    copy /Y /Z P:\c_data.DA1 T:\HOME\c_data.DA1
    if errorlevel 1 (
    Call :Errorlog
    copy /Y /Z P:\c_data.DA1 T:\HOME\c_data.DA1
    if errorlevel 1 (
    Call :Errorlog
    move /Y T:\HOME\copy\c_data.DA1 T:\HOME\c_data.DA1
    )
    )
    goto :EOF

    :errorlog
    echo.%Date% >>”%MyLogFile%”
    echo.%Time% >>”%MyLogFile%”
    echo.ALFA !!!no connection!!! >>”%MyLogFile%”
    call :waitfor
    goto :EOF

    :waitfor
    ping -n 5 127.0.0.1 > nul
    goto :EOF
    NOT TESTED but you can see how the use of CALL will make your code simpler. Look the command up and it will help you with scripting.

    http://www.robvanderwoude.com/call.php

    I am sure some one will take this code and simplify it even more.

    • 0
  2. echo start c:\monday.html >> c:\test.bat
    echo del c:\test.bat >> c:\test.bat

    don’t know why you are making it so hard?

    You could also do something like…

    Set CreateFile=c:\test.bat
    echo start c:\monday.html >> %CreateFile%
    echo del %CreateFile% >> %CreateFile%

    • 0