NT Batch file to delete subdirectories

I need a batch file to delete the contents of permanent sudirectories on a shared network folder.  I'm using NT.  What I want in English is:
   
        delete everything in shared\trainx

 where trainx is a series of 10 - 20 folders.
reginawaltonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

reginawaltonAuthor Commented:
Adjusted points to 100
0
reginawaltonAuthor Commented:
Adjusted points to 150
0
bigbadbCommented:
you can use the utility deltree to delete everything including folders in a dir

so say you directory resided in a mapped drive name z:

the batch file would like like the following

cd z:\shared\trainx\
deltree /Y *.*


let me know if you need this utility I can send it to you.  You should be able to find it in win98

Good Luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

gantriisCommented:
Hi reginawalton.

I believe that you need to erase the directories shared\train1 through to shared\train20 but will avoid deleting files under e.g. shared\nottrain ? Right.

I would say that deltree.exe is still very useful. This utility is included with newer versions of MS-DOS (6.0 and newer I think) and Windows 9x. Once you have that utility in place use this command line (provided that you are in a Windows NT command prompt in the directory directly above the directory shared):

for /D %i in (shared\train*) do deltree /Y %i

(the above command is one single line)

If you choose to insert the line in a batch file and then run the batch file, then the line should look like this:

for /D %%i in (shared\train*) do deltree /Y %%i

I tested this on Windows NT 4.0 (where I had a copy of deltree.exe copied to). The command interpreter on Windows 9x might not understand the above used options for the command FOR.

I hope this answers your question?

Cheers
Gantriis
0
reginawaltonAuthor Commented:
Thanks,

I don't know how this really works, but I hope both of you get the points.

I think I need to clarify something.  I want to keep the train folders -- I just want them to be empty.

Will deltree still work.

0
gantriisCommented:
Hi reginawalton.

I think you just rewarded the points to bigbadb.

However. The command I specified will remove the directories as well. I think the easiest solution would be to organize the delete-batch-job in such a way that it does a deltree on all the directory structures to delete and then recreate the "root" directories (your shared\trainx directories) afterwards.

You could do that by making two batch files (containing one and two lines of code each), where the first calls the other:

Contents (one line) of the first batch file (B1.BAT):

for /D %%i in (shared\train*) do B2.BAT %%i

Contents (two lines) of the second batch file (B2.BAT):

deltree.exe /Y %1
mkdir %1

Now simply delete all the files in the shared\trainx directories by running B1.BAT.

The only problem with this method would be that the original directory permissions are lost in case you had made some special access permissions.

Cheers
Gantriis
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Networking

From novice to tech pro — start learning today.