Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dir : check if exist

Status
Not open for further replies.

matrixknow

IS-IT--Management
May 3, 2007
78
Dim strDate As String
strDate = Format(date, "yyyymmdd")
MkDir ("F:\Out\" & strDate)

Code:
strOutput = "F:\Out\" & strDate & "\" & strCode & ".xls"

Hallo, I create a dir to write my files to. The name of the dir is a date field, each day he can create a new dir.
I should find out if the dir already exist yes or no (did I create it today ?). If the dir exist he should not create a new one. How can I found out if the dir exist ?
 
Code:
Dim strDate As String
    strDate = Format(date, "yyyymmdd")
    Dim NewID As String
    Dim newDirSpecial As String
    Dim lastDirSpecial As String
    newDirSpecial = "F:\Out\" & strDate
    lastDirSpecial = Dir(newDirSpecial, vbDirectory)
    'Create new directory if it does NOT already exist
    If lastDirSpecial <> strDate Then
        MkDir newDirSpecial
    End If

Found an example in a previous thread. It works !


Code:
  Dim FSO As FileSystemObject
   If FSO.FolderExists("F:\Out\" & strDate) = False Then
      FSO.CreateFolder ("F:\Out\" & strDate) ' Create subfolder
   End If

? 1. FileSystemObject seems even smarter, shorter but compiler refuse to run, you should modify something to your configuration. Any experience ?
? 2. Is the function DIR reading all the maps under the directory, I suppose
 
1. Either add a reference to the Scripting RunTime or use late binding:
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top