What is difference between File.Exists(“”) and FileInfo exists

后端 未结 6 1538
萌比男神i
萌比男神i 2021-02-13 22:27

I have an *.exe file in \\ProgramFiles(x86)\\MyAppFolder.

In x86 application I check if the file exists (64 bit system). simple:

bool fileExists = File.E         


        
6条回答
  •  不要未来只要你来
    2021-02-13 22:54

    The difference between File.Exists() and new FileInfo().Exists on it's behavior when full path (directory name + file name) is long:

    var f = @"C:\Program Files (x86)\MyAppFolder\many_subfolders\manager.exe";
    
    //f.length > 260 characters
    
    bool fileExists = File.Exists(f); //return false, even if the file exists
    
    // Throw exception: "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
    bool fileInfoExists = new FileInfo(f).Exists;
    

提交回复
热议问题