Directory.GetFiles Returns duplicate file names

I run System.IO.Directory.GetFiles("my_directory_name_on_network") and it works great for most 11320 files in a directory, but one of them is there twice. Has anyone come across this before? Any idea what this could mean? When I look in Windows Explorer, only one file always appears.

UPDATE

In the end, I was able to see this problem in Windows Explorer as well. The same file name is listed there twice.

+4
source share
1 answer

I had the same problem. I repeated Word documents on the local hard drive and did some automation without saving files, just reading them.

I had *.doc files, and some had *.docx . I used

GetFiles ("* doc.");

GetFiles ("* DOCX.");

to process all files. However, the problem was that

GetFiles ("* doc.");

also finds \*.docx files, so .docx files were found twice.

Use something like this:

 var strFileList = Directory.GetFiles(strDrvPth, strExtn).Where(s => s.EndsWith(strExtn.Substring(1))); 

Substring(1) removes the "*" from the extension specification.

0
source

Source: https://habr.com/ru/post/1439910/


All Articles