473,414 Members | 1,692 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,414 software developers and data experts.

GetFiles exception

Hi everyone,

I'm trying to find the fastest way to get all the files from the local c:
drive. I have even considered the api calls findfirst/findnext, but read
that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path 'c:\System
Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,

Chris
Jul 17 '06 #1
7 4270
Put a Try/Catch around that line, then do nothing in the catch. In the code
following the try/catch, make sure you are not relying on GetFiles
succeeding.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
Hi everyone,

I'm trying to find the fastest way to get all the files from the local c:
drive. I have even considered the api calls findfirst/findnext, but read
that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path 'c:\System
Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,

Chris


Jul 17 '06 #2
Hi Marina,

The problem with this solution is that I need the GetFiles to pickup where
it left off.

The end result should be an array that contains every file on my c: drive.

What else can I do?

Thanks,

Chris
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Put a Try/Catch around that line, then do nothing in the catch. In the
code following the try/catch, make sure you are not relying on GetFiles
succeeding.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
>Hi everyone,

I'm trying to find the fastest way to get all the files from the local c:
drive. I have even considered the api calls findfirst/findnext, but read
that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path
'c:\System Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,

Chris



Jul 17 '06 #3
That's not the same as ignoring the error thrown and continue with your
code. Please be clear in what you want to do.

It sounds like you just need this code to work instead of throwing the
exception. In which case, the user your executable is running under needs
sufficient permissions to get all the files on the drive. Right now this
user does not have these permissions.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:Oa*************@TK2MSFTNGP05.phx.gbl...
Hi Marina,

The problem with this solution is that I need the GetFiles to pickup where
it left off.

The end result should be an array that contains every file on my c: drive.

What else can I do?

Thanks,

Chris
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
>Put a Try/Catch around that line, then do nothing in the catch. In the
code following the try/catch, make sure you are not relying on GetFiles
succeeding.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
>>Hi everyone,

I'm trying to find the fastest way to get all the files from the local
c: drive. I have even considered the api calls findfirst/findnext, but
read that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path
'c:\System Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,

Chris




Jul 17 '06 #4


The followinig code works, but I'm looking for something even faster.

Public Function RecursiveSearch(ByRef array As ArrayList, _
ByVal strDir As String, ByVal bwWorker As BackgroundWorker, _
ByVal e As DoWorkEventArgs) As Boolean

Dim dirInfo As New IO.DirectoryInfo(strDir)

' Try to get the files for this directory
Dim pFileInfo() As IO.FileInfo
Try
pFileInfo = dirInfo.GetFiles()
Catch ex As UnauthorizedAccessException
Return False
Exit Function
End Try

' Add the file infos to the array
array.AddRange(pFileInfo)

'report progress, raises progress changed event
bwWorker.ReportProgress(array.Count)

' Try to get the subdirectories of this one
Dim pdirInfo() As IO.DirectoryInfo
Try
pdirInfo = dirInfo.GetDirectories()
Catch ex As UnauthorizedAccessException
Return False
Exit Function
End Try

' Iterate through each directory and recurse
Dim dirIter As IO.DirectoryInfo
For Each dirIter In pdirInfo
If bwWorker.CancellationPending Then
e.Cancel = True
Else
RecursiveSearch(array, dirIter.FullName, bwWorker, e)
End If
Next dirIter
Return True
End Function
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Put a Try/Catch around that line, then do nothing in the catch. In the
code following the try/catch, make sure you are not relying on GetFiles
succeeding.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
>Hi everyone,

I'm trying to find the fastest way to get all the files from the local c:
drive. I have even considered the api calls findfirst/findnext, but read
that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path
'c:\System Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,

Chris



Jul 17 '06 #5
Perhaps a crazy idea... How about getting the result of
dir *.* /b/s
and appling a split function to the result ?

-tom

Marina Levit [MVP] ha scritto:
That's not the same as ignoring the error thrown and continue with your
code. Please be clear in what you want to do.

It sounds like you just need this code to work instead of throwing the
exception. In which case, the user your executable is running under needs
sufficient permissions to get all the files on the drive. Right now this
user does not have these permissions.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:Oa*************@TK2MSFTNGP05.phx.gbl...
Hi Marina,

The problem with this solution is that I need the GetFiles to pickup where
it left off.

The end result should be an array that contains every file on my c: drive.

What else can I do?

Thanks,

Chris
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Put a Try/Catch around that line, then do nothing in the catch. In the
code following the try/catch, make sure you are not relying on GetFiles
succeeding.

"Chris" <co***********@nospam.yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
Hi everyone,

I'm trying to find the fastest way to get all the files from the local
c: drive. I have even considered the api calls findfirst/findnext, but
read that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path
'c:\System Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
Thanks,

Chris

Jul 17 '06 #6
This will work too....

Private FileList As String = ""

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

GetFiles("C:\")
FileList = FileList.TrimEnd(",")
ListBox1.DataSource = FileList.Split(",")

End Sub

Private Sub GetFiles(ByVal Path As String)
Dim SubDirs() As IO.DirectoryInfo
Dim SubDir As IO.DirectoryInfo
Dim Files() As IO.FileInfo
Dim File As IO.FileInfo

Dim CurDir As New IO.DirectoryInfo(Path)

Files = CurDir.GetFiles

If Not Files Is Nothing Then
For Each File In Files
FileList = FileList & File.Name & ","
Next
End If

SubDirs = CurDir.GetDirectories

If Not SubDirs Is Nothing Then
For Each SubDir In SubDirs
Try
GetFiles(SubDir.FullName)
Catch ex As Exception
'Do Nothing
End Try
Next
End If

End Sub

Jul 17 '06 #7

Chris wrote:
Hi everyone,

I'm trying to find the fastest way to get all the files from the local c:
drive. I have even considered the api calls findfirst/findnext, but read
that in VB.net it's best to use the GetFiles function.

I'm using:
Dim files As String() = System.IO.Directory.GetFiles("c:\", "*.*",
IO.SearchOption.AllDirectories)

and get UnAuthorizeException was unhandled: "Access to the path 'c:\System
Volume Information' is denied."

Is there any way I can just ignore the exception and have the program
continue where it left off?
I haven't reied this yet on a boot device, but you can give it a try:

http://groups.google.com/group/micro...ef110c6e2eece5

Jul 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jonathan Allen | last post by:
MSDN> "The matching behavior of searchPattern when the extension is exactly three characters long is different from when the extension is more than three characters long. A searchPattern of exactly...
4
by: FS | last post by:
hi guys i wanna list the files of a user-chosen directory using getfiles(path)... path is in this case SearchFilesDialog.SelectedPath.ToString()... but that causes an exception tellin me that...
2
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search...
1
by: brian | last post by:
I am using the Directory.GetFiles class and am having problems with the overloaded version. I want to search files. I can use the following and it works fine: Directory.GetFiles(Path, k) Path:...
1
by: Starbuck | last post by:
Hi When the routine below is run it gets to the line - Dim fileEntries As String() = Directory.GetFiles(tString) and then freezes, there is no errors etc, the program just stops responding. The...
11
by: al jones | last post by:
I'm using filesystem.getfiles - and so far it's working correctly *however* I'd sure like to be able to pass it, as the last parameter, the extensions (plural) for which I'm looking. I assumed...
13
by: Lance | last post by:
Hi All, I'm working on a program that requires searching multiple drives for multiple file types and cataloging them based on certain geospatial attributes. All together, there are hundreds of...
0
by: GregInHouston2 | last post by:
I am attempting to access the files on a share on a server in my network so I can list the files there on an intranet web page. At this point, the share permissions and the NTFS permissions are...
3
by: Michael Jackson | last post by:
In my .NET 2.0 VS 2005 VB application, I'm using Directory.GetFiles(path) to get all the files in the directory. However, I'm getting an error regarding "Illegal character in Path", even though I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.