Skip to content

Instantly share code, notes, and snippets.

@cathode
Created December 29, 2016 21:23
Show Gist options
  • Save cathode/0ad6fd6ff3f2704f74cf554ed623d20c to your computer and use it in GitHub Desktop.
Save cathode/0ad6fd6ff3f2704f74cf554ed623d20c to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
try
{
var di = new DirectoryInfo(Environment.CurrentDirectory);
Console.WriteLine("Current directory is {0}", di.FullName);
var files = di.GetFiles();
Console.WriteLine("There are {0} files in the current directory. They are: ", files.Length);
foreach (var fi in files)
{
Console.WriteLine(fi.FullName);
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
Console.ReadLine();
}
}
/*
Produces the following output normally:
Current directory is C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug
There are 6 files in the current directory. They are:
C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug\unctest.exe
C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug\unctest.exe.config
C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug\unctest.pdb
C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug\unctest.vshost.exe
C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug\unctest.vshost.exe.config
C:\Users\myuser\Documents\Visual Studio 2015\Projects\unctest\unctest\bin\Debug\unctest.vshost.exe.manifest
But when run on a network share, on windows 7:
Current directory is \\wab10\Temp\myuser
System.IO.DirectoryNotFoundException: Could not find a part of the path '\\wab10
\Temp\myuser'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String origina
lUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`
1 resultHandler, Boolean checkHost)
at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOptio
n searchOption)
at System.IO.DirectoryInfo.GetFiles()
at Program.Main(String[] args)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment