Page 1 of 1

Combining loopreadline with filecopy into subfolders

Posted: 23 Jan 2020, 09:37
by JKnight_xbt33
Hello again,
I am tweaking a script which I got from 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	
	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         


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

Re: Combining loopreadline with filecopy into subfolders  Topic is solved

Posted: 23 Jan 2020, 13:58
by TravisQ
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"	
	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
					,% sourcepath "\investigation reports complete.msg"
					,% A_LoopFileFullPath
first version crap. edited to be better and possibly work

Re: Combining loopreadline with filecopy into subfolders

Posted: 25 Jan 2020, 04:56
by JKnight_xbt33
Thanks for your reply @TravisQ,

The script works perfectly and amazingly.

Thank you

:dance: :bravo: