Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like to clear the contents of some text files that are in several sub-directories across 2 hard drives on my computer. I would like to do this by a batch file for my ease of use / understanding. Here's what I have so far. Can you help me finish writing this code?

echo off
@for /R %%G in (*.txt) do copy NUL "%%G"

I appreciate your quick reply on my last post!

Thank you Chris

share|improve this question

1 Answer 1

Try something like this on for size, it would be called with two arguments

zerofiles G: K:

echo off
rem Go to the right drive
%1
CD \
rem Start iterating over the drive, zeroing text-files
for /R %%G in (*.txt) do copy NUL "%%G"
rem Go to the 2nd drive
%2
CD \ 
for /R %%G in (*.txt) do copy NUL "%%G"

In the above example the "%1" and "%2" variables are the first and second command-line arguments supplied with the batch file. The "%%G" construct is needed because the for loop is being used inside a batch-file where the % character has special meaning.

share|improve this answer
    
Is something missing from here? I see to variables %1 and %2 but what are they in reference to? The Drives? How could that be if the drives aren't specified anywhere in the actual code? Please enlighten me. –  Chris Sep 24 '10 at 3:35
    
Is something missing from here? I see to variables %1 and %2 but what are they in reference to? The Drives? How could that be if the drives aren't specified anywhere in the actual code? Please enlighten me. –  Chris Sep 24 '10 at 3:36
    
I just figured out the concept here, I need to use the drive letter after the command when executing it. %1 = C: %2 = D: for example. –  Chris Sep 24 '10 at 3:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.