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

后端 未结 6 1388
萌比男神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:52

    I've replicated your scenario using the below Linqpad script

    var f = @"C:\Program Files (x86)\MyAppFolder\manager.exe";
    
    bool fileExists = File.Exists(f);
    bool fileInfoExists = new FileInfo(f).Exists;
    
    fileExists.Dump();
    fileInfoExists.Dump();
    

    Ran this both when the file existed and when it did not and both produced the same output each time. Maybe try this on your system and see if you still see differences.

提交回复
热议问题