Directory Files


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Directory Files

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Directory Files

    [Originally posted by Al Lawrence]

    I am looking for a way to determine if a document file I am about to save already exists in a predefined directory. If it does exist I want to modify the file name of the current document and then save it...

    I have the code to do the saving, just need some help with the importing of a list of filenames in a particular directory into an array.

    Any assistance would be appreciated!

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Directory Files

    [Originally posted by Greg DeBacker]

    I quickly modified this code from the VB help file. It can be refined but it does what you want. It lists the files from a directory in to an array. There is another way(s) to tell if a file already exists. I post another message...

    ˙ ˙ Dim MyFile As String, MyPath As String, MyName As String
    ˙ ˙ Dim AllFiles() As String
    ˙ ˙ Dim iCounter As Integer
    ˙ ˙ MyPath = "c:\"˙ ' Set the path.
    ˙ ˙ MyName = Dir(MyPath, vbNormal)˙ ' Retrieve the first entry.
    ˙ ˙ Do While MyName <> ""˙ ' Start the loop.
    ˙ ˙ ˙ ' Ignore the current directory and the encompassing directory.
    ˙ ˙ ˙ If MyName <> "." And MyName <> ".." Then
    ˙ ˙ ˙ ˙ ˙ ' Use bitwise comparison to make sure MyName is a file.
    ˙ ˙ ˙ ˙ ˙ If (GetAttr(MyPath & MyName) And vbNormal) = vbNormal Then
    ˙ ˙
    ˙ ˙ ˙ ˙ ˙ ˙ iCounter = iCounter + 1
    ˙ ˙ ˙ ˙ ˙ ˙ ReDim Preserve AllFiles(iCounter)
    ˙ ˙ ˙ ˙ ˙ ˙ AllFiles(iCounter - 1) = MyName
    ˙ ˙ ˙ ˙ ˙ ˙
    ˙ ˙ ˙ ˙ ˙ End If˙ ' it represents a file.
    ˙ ˙ ˙ End If
    ˙ ˙ ˙ MyName = Dir˙ ' Get next entry.
    ˙ ˙ Loop
    ˙ ˙
    ˙ ˙ For iCounter = LBound(AllFiles) To UBound(AllFiles)
    ˙ ˙ ˙ ˙ Debug.Print AllFiles(iCounter)
    ˙ ˙ Next


    Grex

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Directory Files

    [Originally posted by Greg DeBacker]

    Test to see if WIN.INI exists...

    Dim MyFile As String
    MyFile = Dir("C:\WINDOWS\WIN.INI")
    If Len(Trim$(MyFile)) > 0 Then
    ˙ ˙ MsgBox "File exists"
    End If

    You can also go to greater lengths with the Windows API.

    Grex

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Directory Files

    [Originally posted by Al Lawrence]

    Thank you...

    And thank you to all that have replied!!!!

    Al

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center