Hi Guys,
i need to automate the deletion of folders and files within 90 Home Directories. as the file and folder names can be anything this script has to work on the assumption that files and folder names are not known.
Cheers
Ryan
Hi Guys,
i need to automate the deletion of folders and files within 90 Home Directories. as the file and folder names can be anything this script has to work on the assumption that files and folder names are not known.
Cheers
Ryan
Dunno if this is will help - it's a script I used to run at the end of term. It will delete everything in the folder apart from a folder called 'keep me'
What we used to tell the kids is if you want stuff saved then move it into a folder called 'keep me' as during the holidays this will run in each of their home drives and anything stored thats not in the 'keep me' folder will be deleted.
You can edit it to your own requirements.
It's done in AutoIT
Code:$search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error <> 0 Then ExitLoop If $file = "keep me" Then ContinueLoop If $file = "." Or $file = ".." Then ContinueLoop If StringInStr(FileGetAttrib(@SCRIPTDIR & "\" & $file) , "D") Then DirRemove($file, 1) Else FileDelete(@SCRIPTDIR & "\" & $file) EndIf WEnd FileClose($search)
Thanks for that will try this. will this run as a normal .vbs because i will have to go through Change Advisory Board to get that 3rd party software approved.
Cheers
Ryan
mattx has suggested an AutoIT script so different to vbs but still a scripting language
ok thanks for that guys
Hi People,
would anyone know how to achieve this using VB or Batch Scripts?
Cheers

What exactly do you want it to do? Just delete "everything" under a path? or some things not?
Are the 90 directories expected to be deleted in 1 script? or multiple runs? :P
Steve
Last edited by Steve21; 5th April 2011 at 12:58 PM.
yeah so would like it to delete all folders, subfolders and files but as i mentioned above not sure of the naming of these so it just need work on the assumtion that the names arent known. and obviously it must not delete the Users Home Directory just the folders, sub folders and files
Hope that makes any sense,
Ry
rd /s is the command you want
you could feed this a list of dir names

So will you run this from their home area? or you wanting one that just runs over entire server? Bearing in mind if it has no way of telling what a users home directory is.
If you're going to run it from within their home directory, and just delete everything below it, it's simple script. But if you're wanting it run from "root" as such, you'll need to give some way of knowing how the structure is, else it'll delete everything.
Steve
Thanks for that "somabc" i will have a look at this
Steve,
it will be running from the server. i know the names of the users home folder. just not sure of the naming of the folders and files within them
The code below is written in vbscript. The lines in between the rows of asterisks are examples - repalce them with the folders you want to clean. It will delete everything in (eg) d:\home\user1 but leave d:\home\user1 alone
Code:set ofso=createobject("scripting.filesystemobject") '*********************** delfolder "d:\home\user1" delfolder "d:\home\user2" '*********************** Sub delfolder(x) dim oFolder if ofso.folderexists(x) then set oFolder=ofso.getfolder(x) for each oSubFolder in oFolder.subfolders ofso.deletefolder oSubfolder,true next for each oFile in oFolder.files oFSO.deletefile oFile,true next end if End Sub
doddsworthy (5th April 2011)

Seems I got pipped to the post :P
Could also try it like:
Think that should work, takes directories from the testing.txt file (you need to put them in etc etc)Code:for /F "delims=" %%a in (C:\Testing.txt) do ( for /f "tokens=*" %b in ('dir /b *.*') do RD /S /Q %b for /f "tokens=*" %c in ('dir /b *.*') do del %c )
Removed all directories, and sub folders/files,
then removes any remaining files.
Not tried it for obvious reasons :P So not 100% it works, but might want to test it on a quiet area(Remember it needs direct paths, CMD doesnt support UNC or doesnt seem to)
Steve
doddsworthy (5th April 2011)
If you want this just as a batch script then you could use
This will first delete all files in all sub directories and then it deletes all sub folders too (I couldn't find a command to do both at the same time)Code:@echo off for /f "delims=" %%j in ( ' dir /b /ad' ) do del /f /s /q %%j for /f "delims=" %%j in ( ' dir /b /ad' ) do for /f "delims=" %%i in ( ' dir %%j /b /ad' ) do rd /s /q "%%j\%%i"
so if you had for example a folder structure:-
D
--users
----y2010
------pupil1
------pupil2
----y2009
------pupil3
------pupil4
----y2008
------pupil5
------pupil6
If you ran the batch file from inside each of the y2010, y2009 and y2008 folders then it would go into each sub folder (e.g. pupil1, 2, etc...) and empty both files and folders while leaving the pupil1, pupil2 folders in place.
Obviously you need to be very careful with a batch file like this... running it in the wrong place could be bad![]()
doddsworthy (5th April 2011), Zoom7000 (17th June 2011)
There are currently 1 users browsing this thread. (0 members and 1 guests)