Combining loopreadline with filecopy into subfolders Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Combining loopreadline with filecopy into subfolders

23 Jan 2020, 09:37

Hello again,
I am tweaking a script which I got from https://www.autohotkey.com/boards/viewtopic.php?f=76&t=71180 Thanks @flyingDman for your help with this script:

After trying it nothing happens, the file is not moved to the subfolders. Perhaps I've overcooked it.


goal of script


Read ID numbers from id.text file located inside the source folder.
for each of these ID numbers it will go to the matching subfolder inside the destination.
It will copy the email file called investigation reports complete.msg into each of these subfolders

Code: Select all


sourcepath := " C:\Users\JK\Documents\reports PDFs"
destpath := " C:\Users\JK\Documents\cases\xxxx"

Loop, Files, investigation reports complete.msg
    {
	Loop, Read, C:\Users\JK\Documents\reports PDFs\id.txt	
	regexmatch(A_LoopReadLine,"(\d+)",match)
	num := match1
	filecopy, C:\Users\JK\Documents\reports PDFs\investigation reports complete.msg,% destpath . floor(num/100) "01 - " ceil(num/100) "00\" num "\" A_LoopFileName         
    }

return


Other things i tried


changed regexmatch to RegExReplace(A_LoopReadLine, "\d+",match)
changed num := match1 to num := match

Is there something simple I am missing here?

btw folder structure is like this C:\Users\JK\Documents\cases\2101 - 2200\2199
TravisQ
Posts: 27
Joined: 17 May 2015, 23:51

Re: Combining loopreadline with filecopy into subfolders  Topic is solved

23 Jan 2020, 13:58

This might do what your looking for or be close.

Code: Select all

sourcepath := a_mydocuments "\reports PDFs"
destpath := a_mydocuments "\cases"

Loop, Read,% sourcepath "\id.txt"	
{
	regexmatch(A_LoopReadLine,"(\d+)",num)
	Loop,Files,% destpath "\*",d
	{
		if ( regexmatch(A_LoopFileName,"" SubStr(num,1,2) "\d\d") ) {                  ; edited
			Loop,Files,% destpath "\" A_LoopFileName "\*",d
			{
                                if(  regexmatch(A_LoopFileName,num)  )                                 ; edited
				filecopy
					,% sourcepath "\investigation reports complete.msg"
					,% A_LoopFileFullPath
			}
		}
	}
}
first version crap. edited to be better and possibly work
JKnight_xbt33
Posts: 135
Joined: 18 Sep 2019, 02:06

Re: Combining loopreadline with filecopy into subfolders

25 Jan 2020, 04:56

Thanks for your reply @TravisQ,

The script works perfectly and amazingly.

Thank you

:dance: :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, taddypole, whoops and 211 guests