Newbie Trouble with MoveFile

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
gpulawski
Newbie
Posts: 6
Joined: Mon Sep 10, 2007 3:11 am

Newbie Trouble with MoveFile

Post by gpulawski » Mon Sep 10, 2007 3:23 am

I'm having trouble with getting the MoveFile to work as I think it is described.
I'm trying to copy a pdf file from one folder to another while renaming it.
Syntax presumed to be:
MoveFile>fromvariable containing full path name, tovariable full path.
Any help would be appreciated.

Code: Select all

VBStart

dim thePatient
dim theMRN

Function GetPatient(SubjectString)
Dim ResultString, myRegExp, myMatches, myMatch
Dim myRegExp2, myMatches2
Set myRegExp = New RegExp
myRegExp.Pattern = "((Pt:\s+)|(Patient Name:\s+))\w+"
myRegExp.Global=True
myRegExp.IgnoreCase=True
Set myMatches = myRegExp.Execute(SubjectString)
If myMatches.Count >= 1 Then
	ResultString = myMatches(0).Value
		Set myRegExp2 = New RegExp
		myRegExp2.Pattern = "\w+$"
		Set myMatches2 = myRegExp2.Execute(ResultString)
		If myMatches2.Count >= 1 Then
		   GetPatient = myMatches2(0).Value
		   thePatient=GetPatient
		Else
			GetPatient=""
			thePatient=GetPatient
		End If
		Set myRegExp2=nothing
End If
Set myRegExp=nothing

Set myRegExp = New RegExp
myRegExp.Pattern = "((MR#:\s+)|(Med. Rec. #:\s+))\w+"
myRegExp.Global=True
myRegExp.IgnoreCase=True
Set myMatches = myRegExp.Execute(SubjectString)
If myMatches.Count >= 1 Then
	ResultString = myMatches(0).Value
		Set myRegExp2 = New RegExp
		myRegExp2.Pattern = "\b\d{8}"
		Set myMatches2 = myRegExp2.Execute(ResultString)
		If myMatches2.Count >= 1 Then
		   GetNumb = myMatches2(0).Value
		   theMRN=GetNumb
		Else
			GetNumb=""
			theMRN=GetNumb
		End If
		Set myRegExp2=nothing
End If
Set myRegExp=nothing
end Function

VBEND

// The incoming and outgoing folders:
// Input folder has image PDF's and associated OCR'd Text Files
// Output folder gets only image PDF's that have been renamed with extracted data from OCR'd txt files
// Input folder contains files named:
// PA_2007_07_17_Kelly_0005.pdf, PA_2007_07_17_Kelly_0005.txt, PA_2007_07_17_Kelly_0006.pdf
// PA_2007_07_17_Kelly_0006.txt, PA_2007_08_31_Barkely_0007.pdf, PA_2007_08_31_Barkely_0007.txt


Let>InFolder=C:\Documents and Settings\pulawgr\Desktop\Recognized Text
Let>OutFolder=C:\Documents and Settings\pulawgr\Desktop\Named PDF

Day>the_day
Month>the_month
Year>the_year
let>theDate=%the_year%_%the_month%_%the_day%
GetTime>theTime

//Get a list of text files in InFolder
GetFileList>%InFolder%\*.txt,file_list,;
Separate>file_list,;,files
//Loop through folder list
If>files_count>0
   Let>k=0
   Repeat>k
     Let>k=k+1
     Let>ThisFile=files_%k%
     //Read in the string
	 ReadFile>ThisFile,SubjectString
	 //replace CRLF chars with VBScript equivalents
	 StringReplace>SubjectString,CR," & vbCR & ",SubjectString
	 StringReplace>SubjectString,LF," & vbLF & ",SubjectString
	 //Double quote any quotes for VBScript
	 StringReplace>SubjectString,","",SubjectString
	 //Extract the Data with RegEx
	 VBEval>GetPatient("%SubjectString%"),aName
	 VBEval>theMRN,aNumb
	 //Deduce the associated source PDF file PathName
	 Length>ThisFile,PathLength
	 let>PathLength=PathLength-3
	 MidStr>ThisFile,1,PathLength,PDFName
	 ConCat>PDFName,pdf
	 //Where does it go and what is it to be called.
	 let>DestName=PA_%theDate%_%theTime%_%aName%_%aNumb%_.pdf
	 let>DestFullName=%OutFolder%\%DestName%
	 // Move the file while renaming it and delete the associated ocr text file
	 IfFileExists>PDFName
	 MoveFile>PDFName,DestFullPath
	 	//Here I will delete the text file named ThisFile using DeleteFile>ThisFile
	 Else
	 	 //Here will go DeleteFile>ThisFile log missing pdf file
	 endif
   Until>k=files_count
Endif

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Sep 10, 2007 4:13 am

In your destination file name you include the time acquired using GetTime>. This puts colons (:) in your file's name which is an illegal character. Do a stringreplace> on the GetTime result and maybe use an underscore.

GetTime>theTime
StringReplace>theTime,:,_,theTime

Otherwise, pretty impressive script for a "newbie".

Hope this helps,
Dick

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Sep 10, 2007 7:22 am

If I'm putting the time into a filename I prefer to use the Hour, Min and Sec functions:

Hour>hh
Min>mm
Sec>ss

Let>filename=myfile_%hh%%mm%%ss%.txt
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

gpulawski
Newbie
Posts: 6
Joined: Mon Sep 10, 2007 3:11 am

Post by gpulawski » Mon Sep 10, 2007 7:35 pm

Thank you, thank you. NOW I see it.

Wonderful bit of work this Macro Scheduler. Just purchased it last week and it has saved lots and lots of time.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts