Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Delete Files

Reply
 
Old 12-11-2008   #1 (permalink)
Vexander


 
 

Delete Files

I have a folder for my TS user's profiles, I want to a script that will loop
through all the users folders and go to a specific folder in each directory
and delete it's contents.

Can soeon give me a hand on this please.

Thanx

My System SpecsSystem Spec
Old 12-11-2008   #2 (permalink)
trading_jacks


 
 

Re: Delete Files

On Dec 11, 5:19*am, Vexander <Vexan...@xxxxxx>
wrote:
Quote:

> I have a folder for my TS user's profiles, I want to a script that will loop
> through all the users folders and go to a specific folder in each directory
> and delete it's contents.
>
> Can soeon give me a hand on this please.
>
> Thanx
Since I am not sure of your directory structure, I will just give you
the general ideas and you should be able to modify it from there.

Here is a basic script to find a particular subfolder of a folder:

On Error Resume Next
parentfolder = "C:\parent\"
findfolder = "child2"
fullfindfolder = parentfolder & findfolder
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder(parentfolder)

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
If Subfolder = fullfindfolder Then
FSO.DeleteFolder(fullfindfolder)
set recreatefolder = FSO.CreateFolder(fullfindfolder)
End If
Next
End Sub

Now if you want to base this on the current user, you will need to add
some of this logic:

Set WshNetwork = WScript.CreateObject("WScript.Network")
currentuser = WshNetwork.UserName
fullfindfolder = parentfolder & currentuser & "\" & findfolder
My System SpecsSystem Spec
Old 12-11-2008   #3 (permalink)
Pegasus \(MVP\)


 
 

Re: Delete Files


"Vexander" <Vexander@xxxxxx> wrote in message
news:11F46A0E-3897-40F4-872C-FF59BD153A60@xxxxxx
Quote:

>I have a folder for my TS user's profiles, I want to a script that will
>loop
> through all the users folders and go to a specific folder in each
> directory
> and delete it's contents.
>
> Can soeon give me a hand on this please.
>
> Thanx
A humble batch file might be the simplest solution, e.g. like so:
@echo off
set TSProfiles=D:\TS Users
for /d %%a in ("%TSProfiles%\*.* ") do echo rd /s /q "%%a\Some Folder\Some
Subfolder"

After adjusting Lines 2 and 3 to suit your environment, run the batch file
from a Command Prompt and check its output. If you're happy with the result,
remove the word "echo" in Line 3.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can't delete files General Discussion
can't delete files Vista file management
unable to delete Names of files after deleted files. Vista mail
cant delete files or rename files Vista security
What files keep & what files delete after upgrade ? Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46