I need to copy files and directories within a directory. Suppose there is only one level.
There is a directory C:\AAAA which contains 5 other directories (sub-directories not having other children) and 7 files.
When I call:
System.IO.Directory.GetFileSystemEntries("C:\\AAAA");
which returns an string array. It will contain the entries sorted in dictonary sort order. So when I call a for-each loop:
foreach(string path in System.IO.Directory.GetFileSystemEntries("C:\\AAAA"))
{
//how to determine path is dictonay or file??
}
so from the array returned by System.IO.Directory.GetFileSystemEntries(“C:\AAAA”), how to determine that given path is a path to file or it is a directory?
You could discover if a string represent a file or a directory using FileAttributes.
Using FileAttributes has only one disadvantage against File.Exist or Directory.Exist.
If the file or directory doesn’t exist, it will throw an exception, but based on your code above, there are little possibilities to incur in this situation and File.GetAttributes is very fast compared.