473,750 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3844
David Gluth
46 New Member
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
527
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 highlighting in Microsoft Visual Studio Dot Net Enterprise Architect? I wish to use an alternative extension (or no extension at all) and still get text highlighting that you would find for a .aspx extension. I was originally told to edit the...
1
6023
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 cannot find the file specified." - no ..NET error is thrown, no stack trace, no debugging info... This code works with smaller files. I've configured my web.config to allow the application to accept up to 100MB files, with a timeout of...
1
7505
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 are numeric. For example, valid files are 'abc1234', 'xyz9876' etc. Is there a search pattern I can use with the Directory.getFiles( ) method. Thanks in Advance Prem
0
3120
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 = IsolatedStorageFile.GetStore( IsolatedStorageScope.User | IsolatedStorageScope.Assembly |IsolatedStorageScope.Domain , null, null );
6
27861
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 specified. (Exception from HRESULT: 0x80070002) I checked all the files I need in those paths and nothing is missing in fact. Anyone can help?
2
2259
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 directory, which name contains that string. Here is how I open the file of a directory. How can it be modified to
0
2525
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: RAISERROR (14113, 16, -1, @osql_cmd, 'instdist.out') The details... MSDE2 SP3 Win 2003 STANDARD edition
4
3083
by: pradeep nair | last post by:
HI, How do i find files with .so extension using python .
0
3392
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 your help! --------------------------------------------------------------------------------------------------------------- Hi, I've created a scheduler job with FORFILES command to delete files
1
3096
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 to a dll, I am trying to call a function exposed by this dll. Here at this statement I am getting this "This system cannot find the file specified" HRESULT 0x80070002 exception. Can any one help me in this regard. Thanks & Regs Bharath Reddy...
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9345
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8265
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6811
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.