Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello! I was wondering if there was a way to overwrite a file when using the ">". For example, If i use the command:
ECHO Test > NewFile.txt
it will just add the word "Test" to the end of the existing file (NewFile.txt). Is there a way get it to overwrite the file? I have tried this:
(A file I use to get the first line of files,)
FOR /F "tokens=*" %%A IN (File.bat) DO ECHO
%%A >> Temorary.txt
COPY Temporary.txt File.bat /Y > NUL
DEL Temorary.txt
but I was wondering if there was a simpler way.Thanks,
Cale

This:
ECHO Test >> NewFile.txt
appends
this:
ECHO Test > NewFile.txt
wipes out the existing file.
If at first you don't succeed, you're about average.M2

Ok, but when I try to change the ">>" in:
FOR /F "skip=2 tokens=*" %%A IN (Old.txt) DO ECHO %%A >> New.txt
to a ">" ,instead of outputting everything but the first and second line in Test.bat (like it's supposed to), it just outputs the last line of Old.txt to the new text file.

Post your EXACT script and fi;e.
Like this:
::== script
for bla
:: END::== textfile
this is some
:: ENDOtherwise I can't tell what is what.
If at first you don't succeed, you're about average.M2

::==Script
FOR /F "skip=2 tokens=*" %%A IN (Test.bat) DO ECHO %%A > Test.bat::==File
---------- Test.BAT
SET Shaggy==N
FOR /F "tokens=*" %%L IN (OldFile) DO CALL :Start_Shaggy %%L
GOTO :End_Shaggy
:Start_Shaggy
IF %Shaggy%==Y GOTO :End_Shaggy
ECHO %* > "NewShaggy"
SET Shaggy=Y
GOTO :End_Shaggy
:End_ShaggyI want to use my script to remove the 1st and 2nd line of that file so it removes the two lines that FIND added. (The blank line and the line that states what file the contents were taken from)
"If it jams, force it. If it breaks, it needed replacing anyway."
-Murphy's Laws

![]() |
![]() |
![]() |

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