473,326 Members | 2,090 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,326 software developers and data experts.

Get list of file name available in the folder

hi guys,

i want to get the name of the files available in the folder

suppose i have D:\Test\Test.txt

i want to check whether it is test.txt file if another file comes other than that it should display me an error
Nov 26 '10 #1
3 1993
Get list file name can

string[] files = Directory.GetFiles(Path);

Check file File.Exist(files[i]);
Nov 26 '10 #2
GaryTexmo
1,501 Expert 1GB
Sorry, I didn't know this was a double post and responded to the wrong one. I'll report the other to be deleted :)

Alex Bug has the correct answer. Here's some links to MSDN for more information on the Directory and File classes, which are super handy.

http://msdn.microsoft.com/en-us/libr...directory.aspx

http://msdn.microsoft.com/en-us/libr...m.io.file.aspx
Nov 26 '10 #3
Hi,
to get list of files in a directory you can use Directory.GetFiles() method.

Expand|Select|Wrap|Line Numbers
  1. string[] files = Directory.GetFiles(path); //gets all files under specified directory.
  2.  
  3. string[] txtFiles = Directory.GetFiles(path, "*.txt"); //gets all .txt files
  4.  
  5. string[] allFiles = Directory.GetFiles(path, "*.txt", SearchOption.AllDirectories); //gets all .txt files from specified directory and its sub-folders.
  6.  
  7. //To check whether file exist:
  8.  
  9. if(File.Exists(@"D:\TEST\TEST.TXT"))
  10. {
  11. //exists
  12. }
  13. else
  14. {
  15. //FileNotFound
  16. }
  17.  
Nov 26 '10 #4

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

Similar topics

2
by: Cindy Liu | last post by:
Hi, If my xml resource file is directly under my project file, I have no problem to load that xml file via Assembly.GetManifestResourceStream. However, after I create a folder under the project...
1
by: davidgordon | last post by:
Hi, I'm using the FileOpenDialog API that everyone has told me about which is posted everywhere on this forum.....works like a dream. When I select a file I get the full path such as : ...
0
by: aris1234 | last post by:
how to rename file name in DB..??? this my code, but this code only save image to folder, can't rename file in DB : <?php //Сheck that we have a file $folder = "../property/$spid";...
1
by: joyfat | last post by:
I'm writting a program for upload file to Web server first I new a file folder name Report on my Web Server and then new many sub file folder in the Report file folder WebServer -- Report ...
3
by: vellyna | last post by:
how to appear path file name? for example, i have select "books" from list, then i browse the file.. after browse the file, i want to appear the path file name that will save the file in a...
11
by: alivip | last post by:
how to ingrate my code to read text in in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name Camry and...
16
by: John | last post by:
I am looking for VBA code that will work with Access 2003 to enable dragging and dropping a file/folder name from Windows XP Explorer into an Access form's text box. This is a common functionality...
10
by: Keith G Hicks | last post by:
I'm hoping there's a simple way to do this. I need to show a dummy image in an asp image object if the file is missing. Here's my asp.net 2.0 markup: <asp:Image ID="imgGrad" runat="server"...
3
by: selvialagar | last post by:
Hi.............. I need to extract a textfile (.txt) file alone from the application startup path. That is I stored a text file in d:\text\inputfile.txt. The folder contains a text file.but i...
16
by: ssecorp | last post by:
Is there a way to view all the modules I have available for import from within Python? Like writing in the interpreter: import.modules Also, is there anything like Cpan for Python?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.