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......

Recommended Answers

All 8 Replies

What is the purpose of this file?

hi

do u mount the network drive?

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

example

first import

Imports System.IO

then

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
            Me.ListBox1.Items.Add(strfind(i).ToString())
        Next

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

sandeepparekh9

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()
            Me.ListBox1.Items.Add(drive)
        Next

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 )
Next
Next
Next

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: "

        Try
            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()
                Next

            Next

        Catch ex As Exception

        End Try

        MessageBox.Show(message)
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.