Code for Working with Files under a Directory?



Code for Working with Files under a Directory?..

Answer / murty

Suppose that you want to list all BMP files under the
f:\Pictures directory. You can write a code as shown in the
code snippet given in Listing 3:

Listing

DirectoryInfo dir = new DirectoryInfo(@"F:\WINNT");
FileInfo[] bmpfiles = dir.GetFiles("*.bmp);
Console.WriteLine("Total number of bmp files",
bmpfiles.Length);
Foreach( FileInfo f in bmpfiles)
{
Console.WriteLine("Name is : {0}", f.Name);
Console.WriteLine("Length of the file is : {0}",
f.Length);
Console.WriteLine("Creation time is : {0}",
f.CreationTime);
Console.WriteLine("Attributes of the file are : {0}",
f.Attributes.ToString());
}

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More C Sharp Code Interview Questions

Code for Reading and writing from a file in c#?

1 Answers  


Hello Sir, Thanks for the Solution but, can you pls. Explain the coding for the Static Function & static variable from the below coding....waiting for Ans. class fact { public static void Main() { fact f=new fact(); int x=1; //Declaration of x as 1 int k=Convert.ToInt32(Console.ReadLine()); for(int i=1;i<=k;i++) { x= x *i; } System.Console.WriteLine(x); } }

0 Answers  


How to export 2 datatables of a single dataset to 2 different worksheets of a single MSExcel file ?

0 Answers   Eastcom Systems,


write a Program to copy the string using switch case.

0 Answers   Mind Tree, Wipro,


Write a function which accepts a sentence as input parameter.Each word in that sentence is to be reversed. Space should be there between each words.Return the sentence with reversed words to main function and produce the required output. for eg:- i/p: jack jill jung kill o/p: kcaj llij gnuj llik

1 Answers   Mind Tree,


Write a program to count the number of characters, number of words, number of line in file.

2 Answers   Mind Tree,


Write a program to count 3Letter, 4Letter and 5Letter words from a file and print the number of 3Letter, 4Letter and 5Letter words. Delimiter is space, tab, hifen. Also we should not consider the line in the file after we encounter # in that line.

0 Answers   Mind Tree,


Code for Working with Files under a Directory?

1 Answers  


Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#

1 Answers  


. Write a program to print the following outputs using for loops $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

3 Answers  


Coding for Manipulate XML File Data Using C#?

1 Answers  


Coding for using Nullable Types in C#?

1 Answers  


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)