Computing.Net > Forums > Disk Operating System > Add to text file through a .bat

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.

Add to text file through a .bat

Reply to Message Icon

Name: Larry21
Date: February 10, 2005 at 20:55:33 Pacific
OS: Win XP
CPU/Ram: P4 2.6
Comment:

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-MARTHA

and 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



Sponsored Link
Ads by Google

Response Number 1
Name: jboy
Date: February 10, 2005 at 21:11:18 Pacific
Reply:

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.


0

Response Number 2
Name: Larry21
Date: February 11, 2005 at 01:11:54 Pacific
Reply:

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...


0

Response Number 3
Name: Mechanix2Go
Date: February 11, 2005 at 02:19:21 Pacific
Reply:

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


0

Response Number 4
Name: rockyrak
Date: February 11, 2005 at 09:56:59 Pacific
Reply:

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


0

Response Number 5
Name: jboy
Date: February 11, 2005 at 10:23:56 Pacific
Reply:

.. 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.


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: February 11, 2005 at 22:42:04 Pacific
Reply:

OK,

Help me out here.

In what way are these different in DOS vs XP:

echo
>>
del

I can't wait.

M2


0

Response Number 7
Name: rogerashley
Date: February 12, 2005 at 00:00:11 Pacific
Reply:

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



0

Response Number 8
Name: jboy
Date: February 12, 2005 at 00:25:17 Pacific
Reply:

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.


0

Response Number 9
Name: rogerashley
Date: February 12, 2005 at 00:35:13 Pacific
Reply:

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.



0

Response Number 10
Name: Larry21
Date: February 13, 2005 at 04:56:29 Pacific
Reply:

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


0

Response Number 11
Name: Mechanix2Go
Date: February 13, 2005 at 05:11:27 Pacific
Reply:

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


0

Response Number 12
Name: Larry21
Date: February 13, 2005 at 05:23:51 Pacific
Reply:

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


0

Response Number 13
Name: Mechanix2Go
Date: February 13, 2005 at 05:47:52 Pacific
Reply:

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


0

Response Number 14
Name: Larry21
Date: February 13, 2005 at 05:58:20 Pacific
Reply:

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


0

Response Number 15
Name: jboy
Date: February 13, 2005 at 10:42:48 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Add to text file through a .bat

Add commands to text file, how? www.computing.net/answers/dos/add-commands-to-text-file-how/14102.html

Batch file to create/edit text file www.computing.net/answers/dos/batch-file-to-createedit-text-file/9206.html

Find and Replace with a BAT file?!!!! www.computing.net/answers/dos/find-and-replace-with-a-bat-file/3291.html