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?

0 Answers   IBM, Xoriant,


How to find No of classes,Packages,No of Methods per Classes and Depth of Inheritance for selecting source code in windows form application using c# .net? (Source code is input Program. It may be Java or .net) Please help me..) Thanks..)

0 Answers  


How to Create a Treeview Menu in ASP.NET with C#?

1 Answers  


I am developing a web application using google map api.I want to update the map inside the div control within update panel. I got other controls updated but map doesn't get updated.I do not not want to update map whenever unnecessary controls are fired at server side.How could it be achieved?

0 Answers  


program to reverse the order of words in a string.

2 Answers   Mind Tree,


Coding for Manipulate XML File Data Using C#?

1 Answers  


Code for Searching for Multiple Matches with the MatchCollection Class?

0 Answers   TCS,


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

3 Answers  


Write a program to convert postfix expression to infix expression.

0 Answers   Mind Tree,


How to add a value from textBox over an existing certain column in SQL Server

0 Answers  


How to Create Files by Using the FileInfo Class?

1 Answers  


Write a function which accepts list of nouns as input parameter and return the same list in the plural form. Conditions: i) if last letter is r then append s ii) if word ends with y then replace it by ies iii) call this function in main() and produce the required output. for eg:- if chair is input it should give chairs as output.

0 Answers   Mind Tree,


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)