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)
}