Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Possible to create a batch file to delete the contents of a text file?

  • 07-06-2007 4:18pm
    #1
    Registered Users, Registered Users 2 Posts: 2,719 ✭✭✭


    Im using a program which writes ten lines of data to a text file called a.txt but the next time I use this program, it adds another 10 lines of data instead overwriting the original 10 lines. So im wondering can anyone tell me is their any way to create a batch file to erase all the data in a txt file without deleting the actual file itself. So I can run a batch file, and their will only be 10 lines at most in the text file after I run this program.

    if anyone can help it would be appreciated!


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    I presume you're adding to the file using piping? Delete and recreate the file?


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Easy enough.
    REM -- First thing we need to do is delete the file. We're going to rename it instead of deleting it, just in case we need it.
    
    rename a.txt a.txt.bak
    
    REM -- Now we need to create a new blank file called "a.txt"
    
    cmd /c > a.txt
    
    REM -- Now we can run our program
    
    program.exe
    


  • Registered Users, Registered Users 2 Posts: 2,719 ✭✭✭kaisersose77


    thanks for the replies

    well this below seems to work fine

    copy /Y a2.txt a.txt

    with a2.txt being an empty file

    so a.txt is emptied when the batch file is run


  • Registered Users, Registered Users 2 Posts: 21,499 ✭✭✭✭Alun


    thanks for the replies

    well this below seems to work fine

    copy /Y a2.txt a.txt

    with a2.txt being an empty file

    so a.txt is emptied when the batch file is run

    Easier way is to do a COPY /Y NUL a.txt

    No need for a separate file a2.txt then :)


Advertisement