ADIR() and SYS(2000) behaves like the DIR command.
Dir command have a MS-DOS legacy, which carry a CP/M one.
http://blogs.msdn.com/b/oldnewthing/archive/2007/12/17/6785519.aspx
The behavior can be unexpected for files whose name contains spaces, have more than 12 characters, or the extension is longer than 3 characters.
And that's because the generated 8.3 short names
This https://support.microsoft.com/en-us/kb/142982 gives a clue about how short names are generated, but is not exhaustive.
When the folder or computer searched with ADIR() or SYS(2000) support short names, files whose short name respect the mask, will be included in the final result.
Moreover, the result include files whose short name contains characters included in the mask, even these characters are not part of the long name.
A classic example is the ~1(2,3..) suffix
http://stackoverflow.com/questions/11107044/strange-windows-dir-command-behavior
This behavior can be stopped, by removing the support for short names.
To remove short names for a single directory
DECLARE INTEGER ShellExecute IN SHELL32.DLL INTEGER nWinHandle,STRING cOperation,STRING cFileName,STRING cParameters,STRING cDirectory,INTEGER nShowWindow
ShellExecute(0,"runas","fsutil","8dot3name strip " + lcPathToDesiredDirectory,"",1)
1) example for ADIR()
******************
* Begin ADIR() example
******************
STRTOFILE("","aabb.xl")
STRTOFILE("","aa bb.xl")
STRTOFILE("","aabb.xls")
STRTOFILE("","aa bb.xls")
STRTOFILE("","aabb.xlsx")
STRTOFILE("","aa bb.xlsx")
STRTOFILE("","aabb.xlsxp")
STRTOFILE("","aa bb.xlsxp")
STRTOFILE("","aabb.xlsxpm")
STRTOFILE("","aa bb.xlsxpm")
*!* On my PC, this is the result of
*!* DIR a*.* /x
*!* 17.09.2015 10:35 0 AABB~1.XL aa bb.xl
*!* 17.09.2015 10:35 0 AABB~1.XLS aa bb.xls
*!* 17.09.2015 10:35 0 AABB~3.XLS aa bb.xlsx
*!* 17.09.2015 10:35 0 AA3C12~1.XLS aa bb.xlsxp
*!* 17.09.2015 10:35 0 AA96D4~1.XLS aa bb.xlsxpm
*!* 17.09.2015 10:35 0 aabb.xl
*!* 17.09.2015 10:35 0 aabb.xls
*!* 17.09.2015 10:35 0 AABB~2.XLS aabb.xlsx
*!* 17.09.2015 10:35 0 AABB~4.XLS aabb.xlsxp
*!* 17.09.2015 10:35 0 AA84DD~1.XLS aabb.xlsxpm
?ADIR(la,"*.xl") && 2
?ADIR(la,"*.xls") && 8
?ADIR(la,"*.xlsx") && 2
?ADIR(la,"*.xlsxp") && 2
?ADIR(la,"*.xl?") && 10
?ADIR(la,"*.xl*") && 10
WAIT
?ADIR(la,"a*.xl") && 2
?ADIR(la,"a*.xls") && 8
?ADIR(la,"a*.xlsx") && 2
?ADIR(la,"a*.xlsxp") && 2
?ADIR(la,"a*.xl?") && 10
?ADIR(la,"a*.xl*") && 10
WAIT
?ADIR(la,"*b*.xl") && 2
?ADIR(la,"*b*.xls") && 5
* DIR "*b*.xls" /x
* aabb.xls
* aa bb.xls
* aabb.xlsx
* aa bb.xlsx
* aabb.xlsxp
?ADIR(la,"*b*.xlsx") && 2
?ADIR(la,"*b*.xlsxp") && 2
?ADIR(la,"*b*.xl?") && 7
* DIR "*b*.xl?" /x
* aabb.xl
* aa bb.xl
* aabb.xls
* aa bb.xls
* aabb.xlsx
* aa bb.xlsx
* aabb.xlsxp
?ADIR(la,"*b*.xl*") && 10
WAIT
?ADIR(la,"*b.xl") && 2
?ADIR(la,"*b.xls") && 2
?ADIR(la,"*b.xlsx") && 2
?ADIR(la,"*b.xlsxp") && 2
?ADIR(la,"*b.xl?") && 4
?ADIR(la,"*b.xl*") && 10
WAIT
?ADIR(la,"*1.xl") && 1
?ADIR(la,"*1.xls") && 4
?ADIR(la,"*1.xlsx") && 0
?ADIR(la,"*1.xlsxp") && 0
?ADIR(la,"*1.xl?") && 5
?ADIR(la,"*1.xl*") && 5
WAIT
?ADIR(la,"*~?.xl") && 1
?ADIR(la,"*~?.xls") && 7
?ADIR(la,"*~?.xlsx") && 0
?ADIR(la,"*~?.xlsxp") && 0
?ADIR(la,"*~?.xl?") && 8
?ADIR(la,"*~?.xl*") && 8
WAIT
?ADIR(la,"*D*.xls") && 2
* DIR "*D*.xls" /x
* aa bb.xlsxpm aka AA96D4~1.XLS
* aabb.xlsxpm aka AA84DD~1.XLS
?ADIR(la,"????.xls") && 1
?ADIR(la,"?????.xls") && 2
?ADIR(la,"??????.xls") && 5
* DIR "??????.xls" /x
* aabb.xls
* aa bb.xls aka AABB~1.XLS
* aabb.xlsx aka AABB~2.XLS
* aa bb.xlsx aka AABB~3.XLS
* aabb.xlsxp aka AABB~4.XLS
?ADIR(la,"????????.xls") && 8
* all except the one with xl as extension
******************
* End ADIR() example
******************
2) Example for SYS(2000)
******************
* Begin SYS(2000) example
******************
STRTOFILE("","aabb.xl")
STRTOFILE("","aa bb.xl")
STRTOFILE("","aabb.xls")
STRTOFILE("","aa bb.xls")
STRTOFILE("","aabb.xlsx")
STRTOFILE("","aa bb.xlsx")
STRTOFILE("","aabb.xlsxp")
STRTOFILE("","aa bb.xlsxp")
STRTOFILE("","aabb.xlsxpm")
STRTOFILE("","aa bb.xlsxpm")
*!* On my PC, this is the result of
*!* DIR a*.* /x
*!* 17.09.2015 10:35 0 AABB~1.XL aa bb.xl
*!* 17.09.2015 10:35 0 AABB~1.XLS aa bb.xls
*!* 17.09.2015 10:35 0 AABB~3.XLS aa bb.xlsx
*!* 17.09.2015 10:35 0 AA3C12~1.XLS aa bb.xlsxp
*!* 17.09.2015 10:35 0 AA96D4~1.XLS aa bb.xlsxpm
*!* 17.09.2015 10:35 0 aabb.xl
*!* 17.09.2015 10:35 0 aabb.xls
*!* 17.09.2015 10:35 0 AABB~2.XLS aabb.xlsx
*!* 17.09.2015 10:35 0 AABB~4.XLS aabb.xlsxp
*!* 17.09.2015 10:35 0 AA84DD~1.XLS aabb.xlsxpm
? MyAdir("*.xl") && 2
?MyAdir("*.xls") && 8
?MyAdir("*.xlsx") && 2
?MyAdir("*.xlsxp") && 2
?MyAdir("*.xl?") && 10
?MyAdir("*.xl*") && 10
WAIT
?MyAdir("a*.xl") && 2
?MyAdir("a*.xls") && 8
?MyAdir("a*.xlsx") && 2
?MyAdir("a*.xlsxp") && 2
?MyAdir("a*.xl?") && 10
?MyAdir("a*.xl*") && 10
WAIT
?MyAdir("*b*.xl") && 2
?MyAdir("*b*.xls") && 5
* DIR "*b*.xls" /x
* aabb.xls
* aa bb.xls
* aabb.xlsx
* aa bb.xlsx
* aabb.xlsxp
?MyAdir("*b*.xlsx") && 2
?MyAdir("*b*.xlsxp") && 2
?MyAdir("*b*.xl?") && 7
* DIR "*b*.xl?" /x
* aabb.xl
* aa bb.xl
* aabb.xls
* aa bb.xls
* aabb.xlsx
* aa bb.xlsx
* aabb.xlsxp
?MyAdir("*b*.xl*") && 10
WAIT
?MyAdir("*b.xl") && 2
?MyAdir("*b.xls") && 2
?MyAdir("*b.xlsx") && 2
?MyAdir("*b.xlsxp") && 2
?MyAdir("*b.xl?") && 4
?MyAdir("*b.xl*") && 10
WAIT
?MyAdir("*1.xl") && 1
?MyAdir("*1.xls") && 4
?MyAdir("*1.xlsx") && 0
?MyAdir("*1.xlsxp") && 0
?MyAdir("*1.xl?") && 5
?MyAdir("*1.xl*") && 5
WAIT
?MyAdir("*~?.xl") && 1
?MyAdir("*~?.xls") && 7
?MyAdir("*~?.xlsx") && 0
?MyAdir("*~?.xlsxp") && 0
?MyAdir("*~?.xl?") && 8
?MyAdir("*~?.xl*") && 8
WAIT
?MyAdir("*D*.xls") && 2
* DIR "*D*.xls" /x
* aa bb.xlsxpm aka AA96D4~1.XLS
* aabb.xlsxpm aka AA84DD~1.XLS
?MyAdir("????.xls") && 1
?MyAdir("?????.xls") && 2
?MyAdir("??????.xls") && 5
* DIR "??????.xls" /x
* aabb.xls
* aa bb.xls aka AABB~1.XLS
* aabb.xlsx aka AABB~2.XLS
* aa bb.xlsx aka AABB~3.XLS
* aabb.xlsxp aka AABB~4.XLS
?MyAdir("????????.xls") && 8
* all except the ones with xl as extension
FUNCTION MyAdir
LPARAMETERS lcMask
LOCAL lnCount
lnCount = 0
IF !EMPTY(SYS(2000,m.lcMask))
lnCount = 1
DO WHILE !EMPTY(SYS(2000,m.lcMask,1))
lnCount = m.lnCount + 1
ENDDO
ENDIF
RETURN m.lnCount
ENDIF
******************
* End SYS(2000) example
******************
Paul Gibson's thread about it
Niciun comentariu:
Trimiteți un comentariu