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 all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
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 5:18pm
    #1
    Registered Users, Registered Users 2 Posts: 2,711 ✭✭✭


    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,711 ✭✭✭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,486 ✭✭✭✭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