473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to find files on Harddisk with specified extension

Hi,
I've a problem which is I need to find file with specified extensions on Harddisk ( on all drives )
please can any one help me
Oct 26 '10 #1
1 3829
Expand|Select|Wrap|Line Numbers
  1.     Dim ListOfFileTypes() As String
  2.  
  3.     Private Sub ListFiles()
  4.         ' an array to hold the file types I am searching for
  5.         Array.Resize(ListOfFileTypes, 2)
  6.         ListOfFileTypes.SetValue("*.Wav", 0)
  7.         ListOfFileTypes.SetValue("*.PDF", 1)
  8.  
  9.         ' Loop throug all the drives on the computer
  10.         For Each drive As System.IO.DriveInfo In My.Computer.FileSystem.Drives
  11.             If drive.IsReady = True Then
  12.                 ' search for files in the root of the drive
  13.                 SearchRoot(drive.Name)
  14.                 For Each SubDir As String In My.Computer.FileSystem.GetDirectories(drive.Name)
  15.                     ' search for files in the folders
  16.                     SearchDirectories(SubDir)
  17.                 Next
  18.             End If
  19.         Next
  20.  
  21.     End Sub
  22.  
  23.     ' MsgBox used here for simplicity - replace with routine to store / display the files as you wish
  24.     Private Sub SearchRoot(ByVal RootDir As String)
  25.         For Each FileName As String In My.Computer.FileSystem.GetFiles(RootDir, FileIO.SearchOption.SearchTopLevelOnly, ListOfFileTypes)
  26.             MsgBox(FileName)
  27.         Next
  28.     End Sub
  29.  
  30.     Private Sub SearchDirectories(ByVal SubDir As String)
  31.         Try
  32.             For Each FileName As String In My.Computer.FileSystem.GetFiles(SubDir, FileIO.SearchOption.SearchAllSubDirectories, ListOfFileTypes)
  33.                 MsgBox(FileName)
  34.             Next
  35.         Catch ex As Exception
  36.             ' Typically an error here is access denied issued by some system folders
  37.             ' This catch will list the folder that wasn't saerched and why whith your file list
  38.             MsgBox("## " & ex.Message & " " & SubDir)
  39.         End Try
  40.     End Sub
  41.  
Oct 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alan Cantor | last post by:
Still trying to figure this one out: I want to edit aspx files that do not have the .aspx extension. Is this possible while still getting the statement completion, text colorization and...
1
by: EdwardSegovia14 | last post by:
Hi, I've written code that uploads files in .NET to the server. When uploading large files (approx 45MB), something goes wrong and a blank white page is returned with one sentect, "The system...
1
by: Prem | last post by:
Hi, I need to search a particular directory for all the files that do not have any extension and have a specific naming convension. The first 3 characters of the file name are alpha and the rest...
0
by: SampathTangudu | last post by:
Hi, We are trying to use the Hash Tables for passing information from one aspx page to another aspx page. We are using the below code. IsolatedStorageFile isoStore =...
6
by: chanmm | last post by:
Dear all, I have run the same web application in my Windows XP Pro without any problem but once I deploy it in Windows 2003 Server the message below appear: The system cannot find the file...
2
by: graphicsxp | last post by:
Hi, How can I open all the files in a directory, which names match a particular string ? Say I have a string like 'a file name to find' and I want to find and open all the files of a given...
0
by: drewmania001 | last post by:
When trying to setup relplication for SQL i am getting the following error. "The system cannot find the path specified" The problem is when trying to run: sp_adddistributiondb line 434:...
4
by: pradeep nair | last post by:
HI, How do i find files with .so extension using python .
0
by: Curious | last post by:
Hi, I'm not sure if this is the right place to post such command issues. If you know a better forum where people respond to messages fairly often, please let me know! Anyway, would appreciate...
1
by: bharathreddy | last post by:
Hai, In general why do we get the "This system cannot find the file specified". exception eventhough all the files used in the C# application are present. Here in my application I am refering...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.