Hello All.

I am having issues with files on a network drive being moved - the file name always remains the same but the location changes. (users move it - much arrrrrrrgggggggg!!)

Is it possible to search through all drives and paths to find FILEX ?

I hope so as this would help me no end.

All code that i have found so far is related to telling you the path of the open file which is no good.

Any help would be great......

if u know the location then just use : System.IO.Directory.GetFiles method


first import

Imports System.IO


Dim s As String = "D:\\Softwares\\"
  Dim strfind() As String
  strfind = System.IO.Directory.GetFiles(s, "*.txt", SearchOption.AllDirectories)
 Dim len As Integer = 0
        Dim i As Integer

        len = strfind.Length - 1

        For i = 0 To len

ListBox will contain all the TxT files in D:\Software directory


the users tend to move the files to stupid and random places for multiple reasons.
So i couldn't say for sure which drive it will be in.

Is it possible to search all available paths in all available drives for filex......

The file is part of a shared report that i build each day.

use this to get all drive list

For Each drive As String In System.IO.Directory.GetLogicalDrives()

so can i therefore do the same for directories with the drive??

this is my thought process - ???

For Each drive As String In System.IO.Directory.GetLogicalDrives()
For each dir as string in system.io.directory.GetDirectories()
for each file as string in system.io.directory()
If file.name = "FILEX.X" then msgbox ("found it @ " & drive & dir )

or something to that effect??????

u can also use something like this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim found() As String

        Dim whattofind As String = String.Empty
        ' supporse u want to find report.xls
        whattofind = "report.xls"

        Dim message As String = "Found At: "

            For Each drive As String In System.IO.Directory.GetLogicalDrives()
                found = System.IO.Directory.GetFiles(drive, whattofind, SearchOption.AllDirectories)

                For i As Integer = 0 To found.GetUpperBound(0)
                    message += found(i).ToString()


        Catch ex As Exception

        End Try

    End Sub
This article has been dead for over six months. Start a new discussion instead.