0

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

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300

1 Answers1

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.

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
  • 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. –  Sep 24 '10 at 03: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. –  Sep 24 '10 at 03: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. –  Sep 24 '10 at 03:41