C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » File Operations »

File search without recursion


Posted Date: 24 Aug 2009    Resource Type: Code Snippets    Category: File Operations
Author: ABitSmartMember Level: Diamond    
Rating: 1 out of 5Points: 10 (Rs 5)



The following code snippet demonstrate how to recursively search for files in a given folder.


string directoryName = @"C:\"; //this is the parent folder name
string fileExt = "*.html"; //this is extension of file to be searched

string fileNames =
Directory.GetFiles(directoryName , fileExt , SearchOption.AllDirectories);

//In the above example, fileNames will be an array of html file names in the parent directory and all subdirectories within it.


The above code demonstrates searching for a file in subdirectories without need of recursion.



Responses

Author: Ramesh N D    28 Aug 2009Member Level: Gold   Points : 0
your code throws Exception... Plz check


Author: ABitSmart    28 Aug 2009Member Level: Diamond   Points : 1
I test my code before posting it. Can you please illustrate what you are doing when the exception is thrown ?


Author: Ramesh N D    28 Aug 2009Member Level: Gold   Points : 1
Error in this line :

string fileNames =
Directory.GetFiles(directoryName , fileExt , SearchOption.AllDirectories);

Exeception : Access to the path 'C:\System Volume Information' is denied.


Author: ABitSmart    28 Aug 2009Member Level: Diamond   Points : 1
I am sorry to say, this does not have any thing to do with my code. Either you do not have access to view the folder or the folder does not exist.


Author: Ramesh N D    29 Aug 2009Member Level: Gold   Points : 0
i am the admin for my system.... shall i know which rights i has to have?..


Author: ABitSmart    29 Aug 2009Member Level: Diamond   Points : 1
From the error it looks like you do not have ACCESS to the folder you are trying to access. Try using a temp folder instead of a system folder and see if it works. As I said, this exception has nothing to do with my code.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Search for files without recursion  .  Search for files  .  C# file search  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Watch your folder
Previous Resource: Copying Directory
Return to Discussion Resource Index
Post New Resource
Category: File Operations


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use