How to scan a file with a long path (more than 256 characters)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Liu

    #1

    How to scan a file with a long path (more than 256 characters)

    I write a program in c#. This program run in my computer (window 7 os) scans the file in the file server(linux os). When the path of file very long, >256 charaters. The program stop run and throw a longpathexcepti on.

    How can I solve this problem?

    Thank you every one!

    Code:
     
    private static void scanFile(string directory)
            {
                List<FileInfo> fileList = new List<FileInfo>();
    
                System.IO.DirectoryInfo di = new DirectoryInfo(directory);
    
                FileInfo[] files = di.GetFiles("*", SearchOption.TopDirectoryOnly);
                DirectoryInfo[] directories = di.GetDirectories("*", SearchOption.TopDirectoryOnly);
    
    
                foreach (FileInfo file in files)
                {
                    fileList.Add(file);
                    logger.Info("Got file: " + file);
                }
    
                inputData(fileList);
    
                foreach (DirectoryInfo dir in directories)
                {
                    scanFile(dir.FullName);
                }
    
                return;
            }//end scanFile method.
Working...