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

DirectoryInfo.GetFiles() Access Denied errors (C#)

Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where the DirectoryInfo.GetFiles returns nothing. When I put a break in and check it out further, it looks like I'm getting ERROR_ACCESS_DENIED when the GetFiles hits certain directories (for example, a System Volume Information directory).

If this were VB I'd just be sloppy and throw an Error Resume Next, lolling all the way to the bank, but obviously I don't have that option in C#. The problem is that using try/catch isn't returning any Exceptions, so I don't know what else to do. Can anyone suggest how I can handle this?

Heres's the code I'm using:

Expand|Select|Wrap|Line Numbers
  1. private void searchFiles(string drive, string extension, string savedFile)
  2. {
  3.             FileInfo saveList = new FileInfo(savedFile);
  4.             StreamWriter w = saveList.CreateText();
  5.             DirectoryInfo di = new DirectoryInfo(drive);
  6.             FileInfo[] lstFiles = di.GetFiles(extension, SearchOption.AllDirectories);
  7.  
  8.             foreach (FileInfo fi in lstFiles)
  9.             {
  10.                 w.WriteLine(fi.FullName);
  11.             }
  12.             w.Close();
  13. }
Oct 13 '07 #1
2 11594
Plater
7,872 Expert 4TB
I believe you can supply permisions to directory/file accesses so that you avoid the "error".

It only returns an empty set for directories you are "not allowed" right, and not the entire thing? so is that really a problem?
Nov 1 '07 #2
Its easy... Use the code below from VB.Net:

Expand|Select|Wrap|Line Numbers
  1. Dim d As New DirectoryInfo(path)
  2.  
  3. For Each Directory As DirectoryInfo In d.GetDirectories()
  4.     If (Directory.Attributes And FileAttributes.System) <> FileAttributes.System Then
  5.         'Your code here!
  6.     End If
  7. Next
Mar 3 '11 #3

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

Similar topics

2
by: Rob | last post by:
Apologies if this is a frequently asked question but i haven't been able to find a satsifactory answer anywhere else at the moment. My problem is that i'm trying to convert an Access97 database...
1
by: Ron | last post by:
I have a asp.net application that uses the above class to open, get status and start/stop a service. I can get the Status of my Service, but can't start/stop it. I keep getting Access Denied...
2
by: byrd48 | last post by:
I have a dll I use in a VS project and it seems at random, when I debug, I will get an application config error (posted below) stating that access is denied. I can debug multiple times and then...
0
by: David Palau | last post by:
We have a internal company WinForms application that makes some calls out to a intranet web service (once at application start-up for some configuration info and then periodically during the life...
0
by: robgallen | last post by:
I'm having a wierd issue trying to launch a robocopy process via a web form. To cut a long story short, it works fine when I run it from the server it is hosted on, but when I access the site from...
2
by: krallabandi | last post by:
Do you have any idea about the below errors? Access to the path "C:\DOCUME~1\P005715\ASPNET\LOCALS~1\Temp\cumhnc6b.cmdline" is denied. Access to the path...
2
by: =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= | last post by:
Hi, I've been trying to use Directory.GetFiles() and also DirectoryInfo.GetFiles() to list files on a remote server using "\\server_name\dir_name" like paths. It works fine on a test windows...
1
by: Rick | last post by:
I've migrated a web site from VS 2003 to VS 2005. After pushing the a Windows Server 2003 web server. The Framework 2.0 web site works when I go to test it. I'll start working on something else...
2
by: P1 | last post by:
Hey guys, I'm totally out of my league here, I don't even know how I got stuck with this problem, it's obviously a webmaster issue and I'm just a lowly net admin. The error: Starts here...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.