Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory vs. DirectoryInfo

Status
Not open for further replies.

hilfy

Active member
Oct 31, 2003
2,564
US
I'm working on a project where I have to programmatically move files from one set of directories to another. Sounds easy, but I'm a bit confused about which object I need to use to get the file information I need to perform this. The directory structures look like this:
Code:
[b]Source Directory[/b]
\\Server1\Archived Reports
  Folder A (random name)
    report A.rpt  (random name)
  Folder B
    report B
  etc...

[b]Destination Directory[/b]
\\Server2\Archived Report
  Folder 1 (category of report)
    report A.rpt (same random name...)
    report B.rpt
  Folder 2 
    report C.rpt
  etc...
Based on information in an Oracle table, I know what the source folder names are and I can determine what the destination folder names will be. I do NOT have the file names! I need to find the name of the report file in each source folder (there will always be only one per folder...the original software wasn't designed very efficiently!) and move it to the predetermined folder on the other server (which will already exist - I've got that piece figured out!)

After looking through the Help and the dearth of info on MS'.NET developers' site, I'm confused over which object to use - Directory or DirectoryInfo - and how to go about get the information about the files so that I can move them to the correct places.

Does anyone have any information that would help me out on this? Thanks!

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
You can get file lists from both Directory and DirectoryInfo. The main difference is what is returned.

Code:
// Directory returns a string array of file names.
string[] files = System.IO.Directory.GetFiles(@"C:\", "*.*");

// DirectoryInfo returns an array of FileInfo
// which is more useful in some sences as it holds
// more data regarding each file, where as the above
// only returns file names.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\");
System.IO.DirectoryInfo[] files = dir.GetFiles("*.*");
Hope this helps... [smile]
 
Last Line should read:

System.IO.FileInfo[] files = dir.GetFiles(@"C:\",@"*.*");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top