Skip to main content

.NET DirectoryInfo.GetFiles() Method Unexpected Behaviour On 3-Letter Extension

According to an article from the MSDN, DirectoryInfo.GetFiles() method will give unexpected behaviour on 3-letter extensions. I quote Microsoft as below:

When using the asterisk wildcard character in a searchPattern (for example, "*.txt"), the matching behavior varies depending on the length of the specified file extension. A searchPattern with a file extension of exactly three characters returns files with an extension of three or more characters, where the first three characters match the file extension specified in the searchPattern. A searchPattern with a file extension of one, two, or more than three characters returns only files with extensions of exactly that length that match the file extension specified in the searchPattern. When using the question mark wildcard character, this method returns only files that match the specified file extension. For example, given two files in a directory, "file1.txt" and "file1.txtother", a search pattern of "file?.txt" returns only the first file, while a search pattern of "file*.txt" returns both files.

The following list shows the behavior of different lengths for the searchPattern parameter:
  • "*.abc" returns files having an extension of .abc, .abcd, .abcde, .abcdef, and so on.
  • "*.abcd" returns only files having an extension of .abcd.
  • "*.abcde" returns only files having an extension of .abcde.
  • "*.abcdef" returns only files having an extension of .abcdef. 

Because this method checks against file names with both the 8.3 file name format and the long file name format, a search pattern similar to "*1*.txt" may return unexpected file names. For example, using a search pattern of "*1*.txt" will return "longfilename.txt" because the equivalent 8.3 file name format would be "longf~1.txt".
http://msdn.microsoft.com/en-us/library/ms143327.aspx

Popular Posts

Ho Ching named 5th most powerful and is mistaken as first lady by Forbes

Forbes named Singapore Prime Minister wife and CEO of Temasek Holdings, Ho Ching, as the 5th most powerful woman in the world. Ho Ching is mistaken as Singapore's first lady! OMG!

I wonder how can Forbes makes such a blunder. For a complete list, refer to here.

How to stop FortiClient from starting automatically?

Installed FortiClient recently but the challenge in disabling the application/service from running automatically on every start-up annoyed me. Attempt to stop 'FortiClient Service Scheduler' only return 'Parameter is incorrect' error message.

An article on Technet help solve my trouble. To stop FortiClient from starting automatically, try the following:
Shut down FortiClient from the system tray.
Run net stop fortishield on command prompt.
Run msconfig.
On msconfig, switch to the Services tab. Clear the FortiClient Service Scheduler check box and click Apply.Run services.msc on command prompt to open up show all available services.Look for FortiClient Service Scheduler. Switch Startup type to Manual.Restart your computer. FortiClient should not be running automatically the next time round. Hope it helps.

ROC Training

13 Aug
I reached 高雄国际航空站 in the morning. Weather was not good and was in fact drizzling. A typhoon had just passed Taiwan. We alighted from the Eva Air plane right onto the runway where we were picked up by a shuttle bus to the arrival hall. The system could have been better if we alighted not on the runway and at a place with shelter.

We then took a bus from the airport straight to our camp, Hengchun Camp. The journey was long. It was too early a morning and so all the shops along the way were not opened. I could see mountains everywhere.

Hengchun Camp was more like an old camp to me. The camp was there for more than 30 years. The external looked average but then the internal revealed itself. More than 50 soldiers were made to live in a bunk! Fans were not enough! Toilets were at another block and so we actually had to cross to another block just to use the toilet. Toilet facilities were bad too. Some of the showers let out water that could boil an egg! Those were condemmed. The first d…