Computing.Net > Forums > Programming > Overwrite with >

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.

Overwrite with >

Reply to Message Icon

Name: CWoodward
Date: February 9, 2006 at 19:43:44 Pacific
OS: Windows XP
CPU/Ram: Intel Celleron
Product: Dell
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: February 9, 2006 at 21:00:57 Pacific
Reply:

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


0

Response Number 2
Name: CWoodward
Date: February 10, 2006 at 13:45:57 Pacific
Reply:

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.


0

Response Number 3
Name: Mechanix2Go
Date: February 11, 2006 at 02:12:20 Pacific
Reply:

Post your EXACT script and fi;e.

Like this:

::== script
for bla
:: END

::== textfile
this is some
:: END

Otherwise I can't tell what is what.


If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: CWoodward
Date: February 11, 2006 at 15:33:56 Pacific
Reply:

::==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_Shaggy

I 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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: Overwrite with >

Novice 'C' question www.computing.net/answers/programming/novice-c-question/7242.html

batch: trim string error www.computing.net/answers/programming/batch-trim-string-error/16536.html

C++ overwrite files with set data www.computing.net/answers/programming/c-overwrite-files-with-set-data/10026.html