Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Writting zeros to files...
Old 09-20-2010, 07:01 PM Writting zeros to files...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Hi,

I have a bunch of text files that I want to write new text to, but I want to clear (delete) content first. I've been studying how to do this and I found a couple of different ways to accomplish this, a batch script way and a bash script way. I would like to do it both ways, but for now, I want to accomplish this via a batch file for the simplicity to understand. How could I do this so the batch file will loop through a couple of different hard drives ( C and D ) to zero out the contents of the text files?

Note: I don't want to delete the files, just the contents of the file so I can re-write new text into the files.

I am pretty stumped on this and need a quick solution.

Thanks for your help in advance!
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-21-2010, 09:14 PM Re: Writting zeros to files...
badams's Avatar
Skilled Talker

Latest Blog Post:
Dum Skype Firefox plugin
Posts: 69
Name: Barry Adams
Location: London
Trades: 0
echo "" >$filename

But generally speaking when a script opens a file in write mode, you have the option to write to the end (append mode), or start over writing from the beginning. So normally you don't need to clear the file first.
__________________

Please login or register to view this content. Registration is FREE
@
Please login or register to view this content. Registration is FREE
(320+ Subjects)
badams is offline
Reply With Quote
View Public Profile Visit badams's homepage!
 
Old 09-21-2010, 11:16 PM Re: Writting zeros to files...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Thank you for the information about appending new data to the old files...That's sounds more like what I am trying to do, but I have to try it out first. Can you show an example how to run a for loop to iterate this process over a couple of different drives while recursing into sub-directories as well?

I could put copy all the files onto one drive and run that code, but being that they are in different folders across a couple of drives, but that will defeat the purpose of my goal.

I've tried this which seems to do part of the job, but getting it to loop (iterate) through a couple of drives won't work for some reason

Must be tired-ness catching up with me.

Code:
 pushd %*
for /r %%j in (*.txt) do if /I not "%%j"=="%~nx0" type nul > "%%j"
popd
I know the iteration part works like this:

Code:
 @for %%d in (C D) do something
but the above code, is not playing nice with me tonight... Anyone care to take a shot at getting it?

Thanks everyone!
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 09-21-2010 at 11:19 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-22-2010, 01:31 AM Re: Writting zeros to files...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
How would it be possible to do a nested loop here?


Code:
for /r %%g in (C D) do command
to iterate through a couple of drives...

and the command below to write zeros to the text files? Another words, Nest both codes together? Can someone enlighten me here?
Code:
@echo off
pushd %*
for /r %%j in (*.txt) do if /I not "%%j"=="%~nx0" type nul > "%%j"
popd
Hope this explains the situation a bit better.

Btw, I'd rather clear the file first, because the data that is to be re written, will be *ALL* fresh as I was told. nothing will be appended, just added as fresh content.

Thanks!
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 09-22-2010 at 01:35 AM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 09-22-2010, 06:02 PM Re: Writting zeros to files...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Anyone?
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Writting zeros to files...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24230 seconds with 12 queries