Administrators Jon Posted December 30, 2013 Administrators Posted December 30, 2013 This is a bug report that surprised me. http://www.autoitscript.com/trac/autoit/ticket/2453 I had no idea that the Windows FindFirstFile/NextFile functions also searched the short filename. I can add a second stage search to ensure that only the long filenames are queried but that may very well break behaviour that people were relying on. I'm thinking that a possible fix would be an optional 2nd parameter for both FileFindFirstFile and FileFindNextFile that indicates only the long file name should be queried. Any better ideas? Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Administrators Jon Posted December 30, 2013 Author Administrators Posted December 30, 2013 Would there ever even be a case of someone wanting to match based on short file name but not long. Hmm, maybe an optional param is overkill for an edge case. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Ascend4nt Posted December 30, 2013 Posted December 30, 2013 Out of curiousity I went ahead and did some tests on my own using a few different methods to try to avoid matching shortnames with a wildcard spec: NtQueryDirectoryFile: I used the FileDirectoryInformation class to purposefully not collect information on short filenames. Result: still matched the wildcard spec against shortnames. FindFirstFileEx (vs. FindFirstFile): I used this with fInfoLevelId (FINDEX_INFO_LEVELS enum) set to FindExInfoBasic, to skip shortnames. Per MSDN it "does not query the short file name," which I had mistakenly assumed to mean that it would not query them as part of the search routine. (Note this option is only recognized on Win7/2008R2+) Result: Still matched the wildcard spec against the shortnames, even if not actually collecting them. I would posit that this is because it calls the lower level NtQueryDirectoryFile to do the searching. So it seems that in order to skip the short filename matches problem, there is no Windows API method that works.. it has to be done using internal checks. You can't even use PathMatchSpec, as that states it works on a maximum of MAX_PATH characters. This would require you to write your own wildcard string match function (or see "Wildcard string compare (globbing)"), or do a conversion to regular expressions and use the PCRE engine. To me, this is way too much extra effort (and code) to workaround a Windows API failure. Better to just document it and let people know about it. While on the subject, it would probably be good to note (and to document) that FileGetShortName() and FileGetLongName() will fail on Windows systems where short filenames are disabled - which is more common in corporate environments where keeping short filenames impacts performance. (See 'Windows Server 2012 File Server Tip: Disable 8.3 Naming (and strip those short names too)' and 'How to Disable the 8.3 Name Creation on NTFS Partitions') P.S. As an aside, on Win7/2008R2+, there's supposed to be performance gains in searching using FindFirstFileEx when dwAdditionalFlags is set to FIND_FIRST_EX_LARGE_FETCH, and fInfoLevelId set to FindExInfoBasic My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
jchd Posted December 31, 2013 Posted December 31, 2013 MS handling of filenames is terrible. Note that you can't even characterize a short name by a tilde, since the tilde is a valid character in filenames. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Richard Robertson Posted January 1, 2014 Posted January 1, 2014 Short names aren't even useful anymore. Why are they a feature? I'd say it'd be better to just document it since all other Windows APIs do the same thing.
BrewManNH Posted January 1, 2014 Posted January 1, 2014 Short names have a use if you want to be lazy and not have to worry about quoting a file path and name to avoid spaces. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Richard Robertson Posted January 1, 2014 Posted January 1, 2014 Short names have a use if you want to be lazy and not have to worry about quoting a file path and name to avoid spaces. But that only works if you know for sure what the short name will become and if you're writing a program, you should never expect the end user to use short names.
BrewManNH Posted January 1, 2014 Posted January 1, 2014 That's where filegetshortname comes in, you don't need to know what it is, you just need to have something to give to that function. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Richard Robertson Posted January 1, 2014 Posted January 1, 2014 So you're wasting extra time getting the short name when you could just put quotes around it?
KaFu Posted January 1, 2014 Posted January 1, 2014 Shortnames are very useful when you work with programs which do not accept unicode input, e.g. like I do in AMT with MPlayer. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now