CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 1999
    Posts
    8

    Display file location

    I have a programme that searches for files and then displays their title and the last date they were modified. The thing I need to do is also display their location within the drives.

    Any Ideas
    Cheers
    v


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Display file location

    When you say that you've already located the files, surely the information is already there in the file path (eg. c:\stuff\something\file.dat) ?

    Or am I missing something here ?


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  3. #3
    Join Date
    Dec 1999
    Posts
    8

    Re: Display file location

    Chris

    The programme I have is doing a recursive search through the C drive and finding documents of a certain type, *.doc,*.scr etc.

    THe code I'm using is similar to whats at www.vb-world.net/ubb/Forum1/HTML/011939.html except that I'm using the input of a text box to search the C Drive.

    Does this make things clearer, I've only been programming for 5 weeks so I'm not always certain what's going on!

    Cheers
    V



  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Display file location

    I see.

    I've copied the code from that posting and changed it for you - on your form, place a ListBox (List1) then copy in the following routine (or overwrite the one you have already there) :



    private Sub LogFilesOfType(byval sType as string, optional byval sInitDir as string = "C:\")
    Dim sSubFolder() as string
    Dim iSubFolder as Long
    Dim sDir as string
    Dim bLogged as Boolean

    on error resume next
    If Right$(sType, 1) <> "," then sType = sType & ","
    If Right$(sInitDir, 1) <> "\" then sInitDir = sInitDir & "\"
    sDir = Dir(sInitDir & "*", vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem + vbDirectory)
    While len(sDir)
    If (GetAttr(sInitDir & sDir) And vbDirectory) = vbDirectory then
    If Left(sDir, 1) <> "." then
    ReDim Preserve sSubFolder(iSubFolder)
    sSubFolder(iSubFolder) = sDir
    iSubFolder = iSubFolder + 1
    End If
    ElseIf InStr(sDir, ".") then
    If InStr(sType, mid$(sDir, InStr(sDir, ".")) & ",") then
    If Not bLogged then
    '
    ' as we're not logging to notepad - ignore this
    '
    ' sLog = sLog & vbCrLf & sInitDir & vbCrLf
    bLogged = true
    End If
    '
    ' Add the full path/filename to the listbox - you could
    ' however do what you like with the full path/filename here
    '
    ' Note that the 'sInitDir' value already has a '\' appended to it
    '
    List1.AddItem sInitDir & sDir
    '
    ' don't bother logging this information to notepad
    '
    'sLog = sLog & " " & Left$(sDir & Space(50), 50) & Chr(9) & Format(FileDateTime(sInitDir & sDir), "HH:MM:SS AM/PM MM/DD/YYYY") & Chr(9) & FileLen(sInitDir & sDir) & vbCrLf
    Caption = "Logged: " & Val(mid$(Caption, 9)) + 1
    End If
    End If
    sDir = Dir
    Wend
    If iSubFolder then
    for iSubFolder = 0 to UBound(sSubFolder)
    Call LogFilesOfType(sType, sInitDir & sSubFolder(iSubFolder))
    next
    End If
    End Sub




    - Should help you out ...



    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  5. #5
    Join Date
    Dec 1999
    Posts
    8

    Re: Display file location

    Chris
    Thanks a millon
    Virginia


  6. #6
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Display file location

    There is no need to write million lines of code. There is also no need to reevent the wheel:
    Go to the menu of vb:
    Project-References
    Search for Microsoft Scripting Runtime
    Check on this to enable it.
    Now go to your program, at the form load event (e.g.) and write these two lines:


    Dim fso as FileSystemObject
    set fso = new FileSystemObject




    After this, type: "fso."
    at the point you press the "." a drop down list will appear with some useful enough properties, methods etc...
    Believe me, this gonna help you enough!!!


    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured