Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'd like to make a batch file which would simply add one or more lines of text to a file. The file does not have a 'txt' extension or any extension for that matter, but contains regular text and I'd like to be able to automatically update the file through running the batch file.For example, lets say the text file contains:
Martha Stewart
220 Mandarine Honey Road
Prince Edwards Island, Fantasy Land
724-ASK-MARTHAand I'd like to add the following line:
Status: in prison
But I dont want to have to go into the file directly but rather have a batch file update this line into it automatically (of course I would have to manually update the batch file, but for technical reasons this would make more sense than updating the file itself.)
Thanks for any help,
Larry

echo Status: in prison >>martha
(martha would be the existing target filename - you can add full path if required)
You are running XP's extended/emulated 'DOS' though, so ymmv
I'm not insensitive, I just don't care.

Thanks a lot
PS- Is there a way to tell the file to erase itself after it does the update? In other words after it appends to the text file there is no need for it anymore so it should just 'self destruct', so to speak...

Hi Larry,
If you going to immediately have it self-destruct, I see little popint in adding the line(s).
But:
::==
echo in prison >> martha
del martha
::==
M2

hi,
if u r going to maintain the file. you need to update the file with the status. if you want to delete it. delete it directly using del command.
Ram

.. whatever that means.
Sure, you can make the batch self-deleting (why though?) but you might get the error 'batch file missing'
You may be able to make use of replaceable parameters:
(prison.bat)
echo Status: in prison >>%1
.. and you'd run it by:
prison martha
That way you'd just specify the target filename as required.
Don't know (& couldn't care) about any ramifications when run under WinXP
I'm not insensitive, I just don't care.

I do not know or care, it does stae not to
post NT Command Prompt Questions in this
Forum in the Posting Warnings

I neither know if there are or aren't differences - and that's not really my concern.
If XP batchers want to pose questions in the wrong forum, then they should be prepared for less than ideal answers.
It's not incumbent upon the contributers here to be versed in other, unrelated Operating Systems. It's not like those OS's don't have their own forums - (I'm pretty sure that they do). I've heard occasional complaints from posters that they fail to receive answers in those forums. That's too bad, but hardly a cause for complaint here.
There is some obligation on the part of the poster to determine the best forum for their particular question, and it begins to stagger the mind that people running XP, NT, Win2K (and no doubt Longhorn next year) continue to ask about "DOS" in this venue.
I'm not insensitive, I just don't care.

Concening longhorn, it does seem that in
the final release there will not even be a
CREATE MSDOS BOOT DISK function, as it is
possible to create an XP NTFS/FAT32 start disk, it
would appear they will finally ditch
emulated DOS, lets hope so.

Wow I didnt mean to get people angry... I tried what you recommended and it worked 100% (regarding writing to the file)
The reason I want the batch file to delete itself is because once it updates the text file it is no longer needed on that computer (suppose I need to update a text file on several computers, this way I could write a bacth file and then run it on each system and it could- ideally- delete itself when its done)
From simple logic it would seem hard for it to do that, being that its like asking a person to look at himself (without a mirror)- ie. only it is giving commands at the moment, so how can it command itself to be deleted (maybe a 'file cannot be deleted' error or something)
According to this explanation, do you guys think that its possible? I did not fully understand the conversation above relating to this.
Thanks again,
Larry

Hi Larry,
Your reasoning is sound.
Since the batch is "in use" the delete may fail.
I would not bet my little finger either way.
Try this as a last line:
del %0.bat
Beware of flying file fragments.
M2

Hmm, it worked. That is strange- it means that a command has no relation to its source (ie. it throws out the command without staying connected to its goal,) and if the process is quick enough and closes before the command has its chance to execute, then it can even 'kill itself' on its own...
It could be that in older OS's (not this XP version of DOS) this would not work because as long as the process has not finished its job it would remain open, whereas in this version it merely shoots commands and has no real control- ie. it is Windows who controls life, (as opposed to life controlling Windows) and Windows accepts the command to delete file x and closes the file because it was its last command, then Windows goes ahead trying to fulfil its final wish. Or something like that.
-Larry

Hi Larry,
I like the way you think.
My guess is [and it's only a guess] that the command interpreter reads the batch into memory and then "acts on it" so the file is no longer "open for reading" and deletion is not prevented.
Just a guess.
Many folks much smarter than me have studied DOS calls for years [and this is emulated DOS service] and have written encyclopedias on the subject.
Too complicated for a shade tree mechanic like me.
FWIW, I don't know if anyone here is angry.
I'm not.
Just some are more socially challenged than others.
M2

Aha (I didnt fully get that, but I think I got the general idea.)
It seems that the more one knows (for real) the more one has the ability to easily lose patience with the 'masses.' This seems to apply very much in the computer field where you now have 2nd graders creating websites with Frontpage and grandmothers asking questions about connecting digital cameras with a USB interface for upload to Windows Etc. Etc.
For someone who was around when computers first began and is truly literate on the ins and outs of the design and implementation of the code and even the hardware, this must really get on their nerves sometimes- as though 'First go study a simple resistor gate; learn what a Capacitor is; understand what the difference is between a Hard Drive and your Memory... then come to me with your problem'
Or it could just be good old arrogance- like the 'Mac crowd' or the 'Unix crowd' or the 'Dos crowd' Etc.
But of course I'm not accusing anyone here of any of that, only verbalising some reflections.
Thanks for the help guys,
Larry

No, not angry (well, I'm not, anyways) - but some of the long time contributers here are a bit exasperated and frustrated (to varying degrees).
Think of it as getting 'wrong number' telephone calls at home. Happens to us all, no big deal - until it starts happening day-in, day-out.
Maybe we should just give up on the idea of a DOS forum entirely and start a brand new 'Command Line' forum - lump it all together & be done with it.
I'm not insensitive, I just don't care.

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

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