Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How can I delete all the folders inside of a public shared folder and leave just the ones I want to stay with a batch file? I already tried to use rd command but it deletes all the folders including the one I'm sharing.

Then you must be writing the batch file wrong. Let's say you have the shared folder: \\server_name\share with several folders underneath it. ex: folder1, folder2 folder3 You want to delete folder1 and folder3 but not folder2. Here's how I would write the batch file:
NOTE: I'm making an assumption here...that you are running the batch file on the computer that has the folders on it.
***begin batch file***@echo off
rem first delete any files in target folders
cd \share\folder1
del /q *.*
cd \share\folder3
del /q *.*
rem now delete the folders
cd \share
rd folder1
rd folder2
rem that's it, you're done***end batch file***
Now, you could use variables so that you could run the batch file from the command prompt and tell it the name of the folders you wish to delete while typing the batch file name to run it.
ex: (we'll call the batch file 'deldir.bat'
deldir folder1 folder2This is a little trickier to setup than the batch file example I put in above and if you don't know how to use variables, well, just leave it alone. As long as it's the same folders you need to delete every time, the above example will work just fine.

We have a share so that everyone can upload anything (open share with full rights). I want to clear that share daily but leave 2 folder on it (my personal 2 folders). The folder name is SHARE and I want to clear everything on it including all folders and files exept this 2 folders. Any idea?

Manny, the easiest way we found during experimentation in school to accomplish what you ask, was to create a simple .BAT that added the ATTRIB +H to all things we didn't want removed, then DEL *.*, then ATTRIB -H to the things we had hidden to end the .BAT. It has worked every time we tried, but nobody has put this into practical application yet. You could attempt this procedure, but be sure to create dummy folders and files first to experiment with until you have the .BAT the way you want it :)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |