FileCopy matching beyond extension pattern given Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
ahketype
Posts: 57
Joined: 27 Oct 2016, 15:06

FileCopy matching beyond extension pattern given

07 Dec 2019, 20:44

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
ahketype
Posts: 57
Joined: 27 Oct 2016, 15:06

Re: FileCopy matching beyond extension pattern given

08 Dec 2019, 05:57

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:
User avatar
Xtra
Posts: 1558
Joined: 02 Oct 2015, 12:15

Re: FileCopy matching beyond extension pattern given

08 Dec 2019, 06:13

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

Return to “Ask For Help”

Who is online

Users browsing this forum: 1100++, Google [Bot], john_c, Rohwedder and 198 guests