Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How to check for the existence of the Temporary folder named Tempo

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


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 Excel Programming 0 May 3rd 09 04:55 PM
Check if folder exists, if yes just copy sheet in to folder? Simon Lloyd[_787_] Excel Programming 3 June 19th 06 03:44 PM
Temporary Folder Location Bill[_30_] Excel Programming 2 January 5th 06 11:08 PM
Can VBA clear the Temporary Internet File folder? quartz[_2_] Excel Programming 1 December 3rd 04 11:57 PM
Checking for the Existence of a Folder Viswanath Tumu Excel Programming 2 April 19th 04 08:31 AM


All times are GMT +1. The time now is 02:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"