[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

NT Batch file to delete subdirectories

Posted on 2000-02-03
6
Medium Priority
?
1,760 Views
Last Modified: 2013-12-23
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.
0
Comment
Question by:reginawalton
  • 3
  • 2
6 Comments
 

Author Comment

by:reginawalton
ID: 2487534
Adjusted points to 100
0
 

Author Comment

by:reginawalton
ID: 2487664
Adjusted points to 150
0
 
LVL 1

Accepted Solution

by:
bigbadb earned 450 total points
ID: 2487689
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:gantriis
ID: 2487728
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
 

Author Comment

by:reginawalton
ID: 2488364
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
 
LVL 2

Expert Comment

by:gantriis
ID: 2488905
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question