How to set two "setworkingdirs"?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
masterkomp
Posts: 1
Joined: 03 May 2024, 14:34

How to set two "setworkingdirs"?

Post by masterkomp » 03 May 2024, 14:39

I want to copy myfile.dox into two locations.
I was trying diffferent ways but none of them was working.
How to set two working dirs?

For example, I want to copy this file into these locations:

setworkingdir,C:\copies
setworkingdir,D:\copies


Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

setworkingdir,C:\copies
~^s::
sleep,500
    filehistory("C:\Users\User\Desktop\myfile.docx")
soundbeep

 FileHistory(FilePattern,BkUpDir="",VerCnt=1,maxdepth=1,curdepth=1)
    {
    static NameNdl:="^(?P<n>.*)_(?P<t>\d{14})(?P<x>\.[^\.]*)?$"
    static PthNdl:="^(?P<dp>(?P<d>\w:\\?|\\\\[^\\]+\\?)?(?P<p>.*\\)?)(?P<nx>(?P<n>[^\\]*?)(?P<x>\.(?!.*\.).*)?)$"
    aTLfromNX:=[]
    (regexmatch(BkUpDir,"[^\\]$") ? (BkUpDir.="\") : "")
    regexmatch(FilePattern,PthNdl,fp_)
    loop,% BkUpDir fp_nx,0,0
        if (regexmatch(a_loopfilename,NameNdl,_))
            aTLfromNX[_n _x].=_t ","
    BkUpDirExist:=BkUpDir="" || FileExist(BkUpDir)
    loop,% FilePattern,0,0
        {
        if (timelist:=aTLfromNX[a_loopfilename])
            if a_loopfiletimemodified in %timelist%
                continue
        if (!BkUpDirExist)
            {
            FileCreateDir,% BkUpDir
            BkUpDirExist:=1
            }
        aTLfromNX[a_loopfilename].=a_loopfiletimemodified ","
        regexmatch(a_loopfilename,PthNdl,_)        
        FileCopy,% a_loopfilefullpath,% BkUpDir _n "_" a_loopfiletimemodified _x
        }
    for orgname,timelist in aTLfromNX
        {
        sort,timelist,D`,
        stringreplace,timelist,timelist,% ",",% ",",UseErrorLevel
        KillCnt:=ErrorLevel-VerCnt
        regexmatch(orgname,PthNdl,_)
        loop,parse,timelist,% ","
            if (a_index<=KillCnt)
                FileDelete,% BkUpDir _n "_" a_loopfield _x
            else
                break
        }
    if (!(curdepth<maxdepth))
        return
    aTLfromNX:=""
    loop,% fp_dp fp_n,2,0
        Func(a_thisfunc).(fp_dp a_loopfilename "\*" fp_x,BkUpDir a_loopfilename "\",VerCnt,maxdepth,curdepth+1)
    }
   
[Mod edit: Moved topic from AHK v2 help to v1 help since this is v1 code.]

User avatar
mikeyww
Posts: 27161
Joined: 09 Sep 2014, 18:38

Re: How to set two "setworkingdirs"?

Post by mikeyww » 03 May 2024, 16:37

Welcome to this AutoHotkey forum!

FileCopy does not require a working directory. You can specify the full path to your destination. You can then use as many such commands as you wish.

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

Post Reply

Return to “Ask for Help (v1)”