Cross-platform development there is a well-known, but because only occasionally troubled, ordinary people do not care about the problem, that is, Windows is not sensitive to file name capitalization, and other platforms are sensitive to file name case. As a result, it may be normal for Windows platform development, but deploying/packaging to other platforms will cause the runtime to load files to fail. I am not very concerned about this problem, is generally packaged/deployed when all files are transferred to lowercase save, loading the file will also be the filename to lowercase. Without this approach, the general company also has a process in place to avoid such problems.
But a good process is also required to carry out, if the implementation is not in place, such as the art of uploading resources do not follow the norms, or planning to fill out the specification, there will be problems. So my former colleague asked me if I had any method of detection, so I tried a bit.
The first thing I think about is the name property of FileInfo, which is to do it, but when it is actually used, it is found that if you create fileinfo in lowercase, the Name property of the FileInfo created is also a lowercase name, not the actual name. Then I thought of the step-by-step traversal of the folder, which can always be case-sensitive to find out if it matches. So after several tests, the problem was solved and the final code was as follows:
Public Static classtools{ Public Static BOOLIscasematch (stringpath) {Path= path. Replace ('\\','/'); string[] pathes = path. Split ('/'); DirectoryInfo dir=NewDirectoryInfo ("."); for(inti =0; I < pathes. Length-1; i++) {directoryinfo[] dirs=dir. GetDirectories (Pathes[i]); if(dirs. Length = =0) return false; DirectoryInfo Dir2=NULL; for(intj =0; J < Dirs. Length; J + +) { if(Dirs[j]. Name = =Pathes[i]) {Dir2=Dirs[j]; Break; } } if(Dir2 = =NULL) return false; Dir=Dir2; } fileinfo[] Files= dir. GetFiles (pathes[pathes. Length-1]); if(Files. Length = =0) return false; for(inti =0; I < files. Length; i++) { if(Files[i]. Name = = Pathes[pathes. Length-1]) return true; } return false; }}
The current version only detects relative paths and cannot detect absolute paths (actual projects loaded with resources typically do not use absolute paths)
Original Detects file name case matching under Windows