PC Review


Reply
Thread Tools Rate Thread

How to check for the existence of the Temporary folder namedTemporary Folder a , 2 and so on before deleting as the name is not fixed

 
 
Yuvraj
Guest
Posts: n/a
 
      3rd May 2009
Hi All,

I am using the following code


Set FSO = CreateObject("scripting.filesystemobject")
FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True

The purpose is that I want to delete the Folder NAmed as Temporay
Directory a and Temporary Directory b.

I want to check the existence of the folder before deleting.

I am wondering how to do it as the name is not constant.

What is constant is Temporary Dirctory and then variable names

I also do not want to delete all the folders.

Hence can some one provide some guidance.

Regards,

Yuvraj

 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      3rd May 2009
This should get you started.

Option Explicit

Sub test()
Dim FSO As Object
Dim myParentFolder As Object
Dim myChildFolder As Object
Dim Verify As VbMsgBoxResult
Dim FoundFolder As Boolean

Set FSO = CreateObject("scripting.filesystemobject")

Set myParentFolder = FSO.Getfolder(Environ("temp"))
Do
FoundFolder = False
For Each myChildFolder In myParentFolder.Subfolders
Debug.Print myChildFolder.Name
If myChildFolder.Name Like "*Temporary Directory*" Then
Verify = MsgBox("Do you want to delete folder: " &
myChildFolder.Name & "?", vbYesNo)
If Verify = vbYes Then
myChildFolder.Delete
FoundFolder = True
Exit For
End If
End If
Next myChildFolder
Loop While Verify = vbYes
End Sub


HTH,
Barb Reinhardt

"Yuvraj" wrote:

> Hi All,
>
> I am using the following code
>
>
> Set FSO = CreateObject("scripting.filesystemobject")
> FSO.DeleteFolder Environ("Temp") & "\Temporary Directory*", True
>
> The purpose is that I want to delete the Folder NAmed as Temporay
> Directory a and Temporary Directory b.
>
> I want to check the existence of the folder before deleting.
>
> I am wondering how to do it as the name is not constant.
>
> What is constant is Temporary Dirctory and then variable names
>
> I also do not want to delete all the folders.
>
> Hence can some one provide some guidance.
>
> Regards,
>
> Yuvraj
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for the existence of the Temporary folder namedTemporary Folder 1,2 and so on As Yuvraj Microsoft Excel Programming 0 3rd May 2009 04:55 PM
Problem deleting Temporary Internet Files from Temp Folder DaffyDŽ Microsoft Windows 2000 7 8th Jan 2009 02:11 AM
Deleting temporary folder Ariel Windows XP Customization 7 1st Dec 2004 02:13 AM
DELETING TEMPORARY FILES FOLDER CONTENT =?Utf-8?B?Sm90ZW5rbw==?= Windows XP General 2 17th Jul 2004 12:35 AM
deleting long named file in temporary internet folder =?Utf-8?B?SEs=?= Windows XP Internet Explorer 2 10th Apr 2004 04:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 AM.