vbscript - VB Script to Delete Sub folders and files from a folder -


i have folder bunch of user folders , files in , need delete out of contents leave folders showing of names.

the folder structure is:

d:\users\aanderson\data\stuff
d:\users\acarlson\data\stuff
d:\users\banderson\data\stuff

and want delete but:

d:\users\aanderson\
d:\users\acarlson\
d:\users\banderson\

i tried couple different scripts pretty emptied entire folder (using test folders of course)

from command line, easiest way is

for /d %a in ("d:\users\*") (pushd "%~fa" && (rmdir . /s /q 2>nul & popd)) 

that is, each of subfolders, place lock in avoid removed. in case, lock pushd can not remove current working folder.

so, same in vbscript

option explicit  dim shell, fso     set shell = wscript.createobject("wscript.shell")     set fso   = wscript.createobject("scripting.filesystemobject")  dim folder     each folder in fso.getfolder("d:\users").subfolders         shell.currentdirectory = folder.path         on error resume next : folder.delete true : on error goto 0     next 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -