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 - Get Folder Names

Reply
 
Old 08-26-2009   #1 (permalink)
James


 
 

Get Folder Names

I want to loop through all of the sub folders in c:\documents and settings\
and get their names. Can this be done with fso.GetFolder? If so, does
anyone have a good link or some sample code I could take a look at?

James



My System SpecsSystem Spec
Old 08-26-2009   #2 (permalink)
mr_unreliable


 
 

Re: Get Folder Names



James wrote:
Quote:

> I want to loop through all of the sub folders in c:\documents and settings\
> and get their names. Can this be done with fso.GetFolder? If so, does
> anyone have a good link or some sample code I could take a look at?
>
> James
>
hi James,

There are several examples to be found in the fso section of the
scripting documentation.

And probably more examples on the ms "Scripting Guys and Girls"
website.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
My System SpecsSystem Spec
Old 08-26-2009   #3 (permalink)
James


 
 

Re: Get Folder Names

I am trying to delete all of the cookies files in everyone's user profile.
Here is what I found but I am getting an error that the path cannot be found
when the code tries to delete the files in the cookies folder. The echo part
works fine. See any problems?

Set objFSO = CreateObject("Scripting.FileSystemObject")

strFolder = "c:\documents and settings\"

Set objFolder = objFSO.GetFolder(strFolder)

Set colFolders = objFolder.SubFolders

For Each objSubFolder In colFolders
If objSubFolder.Path <> "C:\Documents and Settings\Default User" Or
objSubFolder.Path <> "C:\Documents and Settings\All Users" Or
objSubFolder.Path <> "C:\Documents and Settings\LocalService" Or
objSubFolder.Path <> "C:\Documents and Settings\NetworkService" Then
objFSO.DeleteFile(objSubFolder.Path & "\Cookies\*.*")
End If
WScript.Echo objSubFolder.Path
Next

James

"mr_unreliable" <kindlyReplyToNewsgroup@xxxxxx> wrote in message
news:eDCjU%23mJKHA.5956@xxxxxx
Quote:

>
>
> James wrote:
Quote:

>> I want to loop through all of the sub folders in c:\documents and
>> settings\ and get their names. Can this be done with fso.GetFolder? If
>> so, does anyone have a good link or some sample code I could take a look
>> at?
>>
>> James
>
> hi James,
>
> There are several examples to be found in the fso section of the scripting
> documentation.
>
> And probably more examples on the ms "Scripting Guys and Girls"
> website.
>
> cheers, jw
> ____________________________________________________________
>
> You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
> the answers will be applicable to the questions)

My System SpecsSystem Spec
Old 08-26-2009   #4 (permalink)
Tom Lavedas


 
 

Re: Get Folder Names

On Aug 26, 4:44*pm, "James" <donotemai...@xxxxxx> wrote:
Quote:

> I am trying to delete all of the cookies files in everyone's user profile..
> Here is what I found but I am getting an error that the path cannot be found
> when the code tries to delete the files in the cookies folder. The echo part
> works fine. *See any problems?
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> strFolder = "c:\documents and settings\"
>
> Set objFolder = objFSO.GetFolder(strFolder)
>
> Set colFolders = objFolder.SubFolders
>
> * For Each objSubFolder In colFolders
> *If objSubFolder.Path <> "C:\Documents and Settings\Default User" Or
> objSubFolder.Path <> "C:\Documents and Settings\All Users" Or
> objSubFolder.Path <> "C:\Documents and Settings\LocalService" Or
> objSubFolder.Path <> "C:\Documents and Settings\NetworkService" Then
> * objFSO.DeleteFile(objSubFolder.Path & "\Cookies\*.*")
> *End If
> *WScript.Echo objSubFolder.Path
> * Next
>
> James
>
The logic in your IF statement is faulty, which is probably the source
of your problem.

I would suggest you try something more like this instead ...

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\documents and settings\"
Set objFolder = objFSO.GetFolder(strFolder)
Set colFolders = objFolder.SubFolders

For Each objSubFolder In colFolders
strPath = objSubFolder.Path & "\Cookies"
If objFSO.FolderExists(strPath) then
objFSO.DeleteFile strPath & "\*.*"
End If
WScript.Echo strPath
Next
_____________________
Tom Lavedas
My System SpecsSystem Spec
Old 08-27-2009   #5 (permalink)
James


 
 

Re: Get Folder Names

You were right Tom. I fixed the If then logic and all is working great now.
Thanks a ton for cathing that!

James

"Tom Lavedas" <tglbatch@xxxxxx> wrote in message
news:a720f526-d196-4c83-92cf-007696e73f6a@xxxxxx
On Aug 26, 4:44 pm, "James" <donotemai...@xxxxxx> wrote:
Quote:

> I am trying to delete all of the cookies files in everyone's user profile.
> Here is what I found but I am getting an error that the path cannot be
> found
> when the code tries to delete the files in the cookies folder. The echo
> part
> works fine. See any problems?
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> strFolder = "c:\documents and settings\"
>
> Set objFolder = objFSO.GetFolder(strFolder)
>
> Set colFolders = objFolder.SubFolders
>
> For Each objSubFolder In colFolders
> If objSubFolder.Path <> "C:\Documents and Settings\Default User" Or
> objSubFolder.Path <> "C:\Documents and Settings\All Users" Or
> objSubFolder.Path <> "C:\Documents and Settings\LocalService" Or
> objSubFolder.Path <> "C:\Documents and Settings\NetworkService" Then
> objFSO.DeleteFile(objSubFolder.Path & "\Cookies\*.*")
> End If
> WScript.Echo objSubFolder.Path
> Next
>
> James
>
The logic in your IF statement is faulty, which is probably the source
of your problem.

I would suggest you try something more like this instead ...

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\documents and settings\"
Set objFolder = objFSO.GetFolder(strFolder)
Set colFolders = objFolder.SubFolders

For Each objSubFolder In colFolders
strPath = objSubFolder.Path & "\Cookies"
If objFSO.FolderExists(strPath) then
objFSO.DeleteFile strPath & "\*.*"
End If
WScript.Echo strPath
Next
_____________________
Tom Lavedas


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Folder names Vista General
file names and folder names have been changed into some values automatically Vista file management
Folder names Vista mail
Folder names disappeared. Vista General
hidden folder names Vista file management


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