Page 1 of 1

FileCopy matching beyond extension pattern given

Posted: 07 Dec 2019, 20:44
by ahketype
Hi, curious little issue when doing this:

Code: Select all

FileCopy, C:\Blah\*.ctb, C:\NewPath\*.*, 1
Intending to collect all matching files with .ctb extension, but also gets those with extensions .ctb~ .ctb~~ .ctb~~~ .ctb~~~~ ...etc.
Normally, a pattern match like that would require *.ctb*
These are CherryTree backup files, by the way. I also tested with filename.ctbxyz, which also gets copied.
Is it a bug, or am I doing it wrong? (Is there a way to definitively end the pattern given, maybe?)
Cheers
ahketype

Re: FileCopy matching beyond extension pattern given  Topic is solved

Posted: 07 Dec 2019, 20:55
by boiler

Re: FileCopy matching beyond extension pattern given

Posted: 08 Dec 2019, 05:57
by ahketype
Cheers boiler, that explains it, the old 8.3 filenames issue.
Other observations on this for anyone needing to avoid the problem:
In my case, I can just use the specific filenames, as there aren't many of them I want to copy and I know what they're called, and then it doesn't try to match them, just looks for the exact file (so C:\Path\filename.ext as source won't copy a file called C:\Path\filename.ext1). If anyone wanted to copy just the 3-character extension files at run-time but didn't know what they might be, and still avoid 4+ length extensions, they would have to do something like read the filenames into memory (array, string, etc.) and then compute from that list which files to use FileCopy on.
Thanks
ahketype :bravo:

Re: FileCopy matching beyond extension pattern given

Posted: 08 Dec 2019, 06:13
by Xtra
You could check the end of the filenames with SubStr()

Code: Select all

Loop, Files, C:\Blah\*.ctb
{
    file := A_LoopFileLongPath
    if (SubStr(file, StrLen(file) - 3) = ".ctb")
        FileCopy, % file, C:\NewPath\*.*, 1
}
HTH