473,700 Members | 2,501 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 3842
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
6021
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
7451
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
3115
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
27856
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
2256
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
2521
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
3081
by: pradeep nair | last post by:
HI, How do i find files with .so extension using python .
0
3388
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
3093
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
8648
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,...
0
9217
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9078
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8974
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
8928
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
7815
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...
0
5903
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();...
0
4407
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3094
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

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.