Checking a folder exists.

So This script I swear worked before while I initially tested it now I am having issue. Can anyone see anything wrong with this…

To give a little background I am getting some of this information via a third party app passing environment variables to a .sh file that I am exporting to variables that the applescript picks up… I have confirmed dozens of times I am getting the right data for my “switch” checks for true/false and y/n’s.

My problem lies in that on my if not (exists…) then… isn’t working. I know the folder I am looking for isn’t there but yet it doesn’t seem to find that… strange thing is I put in an else display dialog and that doesn’t fire either… weird…

--Order File Copy Folder Creation for Markley Ent BizApp Manufacturing System
--Written by Eric Foust

--Below we will set the varibles from the environment varibles passed into the gFolderCopy.sh file from BizApp. 
--The object after System attibute is what we export the value as from the gFolderCopy.sh file

--BizApp Evo Prams
--/Applications/BizApp/Scripts/gFolderCopy.sh
--env-param: ArtWorkPath=graphicSubArtPath
--env-param: trnsfrchk=ArtTransferCheck
--env-param: CutFile=Proofread:Graphic:CutFile
--env-param: company=CustNumPart:Desc
--env-param: PrintChk=noGraphic



--These are the contents of the shell script
--export ArtWorkPath=$ArtWorkPath
--export trnsfrchk=$trnsfrchk
--export CutFile=$CutFile
--export company=$company
--export orderNumber=$orderNumber
--export orderLineItem=$orderLineItemNumber
--export PrintChk=$PrintChk
--osascript /Applications/BizApp/Scripts/gFolderCopy.scpt



--We will now start setting local varibles based on the evo varibles passed to us by bizapp

--BizApp Varible Name $ArtWorkPath
--This should be be passed from bizapp as the path to the graphics folder.
--export evo var from shell to be ArtWorkPath
set varArtWorkPath to system attribute "ArtWorkPath"

--BizApp Varible Name $trnsfrchk
--This should be be passed from bizapp as y/n.
--export evo var from shell to be trnsfrchk
set varTrnsfrChk to system attribute "trnsfrchk"

--BizApp Varible Name $CutFile
--This should be be passed from bizapp as True/False.
--export evo var from shell to be CutFile
set varCutFile to system attribute "CutFile"

--BizApp Varible Name $company
--This should be be passed from bizapp as the customer name.
--export evo var from shell to be company
set varCompany to system attribute "company"

--BizApp Varible Name $order
--This should be be passed from bizapp as the OrderNumber
--export evo var from shell to be orderNumber
set varOrderNumber to system attribute "orderNumber"

--BizApp Varible Name $order
--This should be be passed from bizapp as the orderLineItemNumber
--export evo var from shell to be orderLineItem
set varOrderLineItem to system attribute "orderLineItem"

--BizApp Varible Name $PrintChk
--This should be be passed from bizapp as the True/False.
--export evo var from shell to be noGraphic
set varPrintChk to system attribute "PrintChk"

--Here we can turn on some debug to see what bizapp passes to the shell and in turn the .scpt
--display dialog "Artwork Path- " & varArtWorkPath & " Transfer Check- " & varTrnsfrChk & " CutFile- " & varCutFile & " Company- " & varCompany & " Order- " & varOrderNumber & " OrderLine- " & varOrderLineItem & " PrintChk- " & varPrintChk



--Here we are going to set some Local Varibles that bizapp did not pass to us.

--Set the Source Folder
--Printer Files
set theFilesForPrint to varArtWorkPath & "/Final Files for Print/" as POSIX file
--Cutting Files
set theCutFiles to varArtWorkPath & "/Cut Files/" as POSIX file


--Set the dest folders
--Print Job Folder
set thePrintJobsPath to "/Volumes/BizApp/Production Files/Print Jobs/" as POSIX file
--Cut Job Folder
set theCutJobsPath to "/Volumes/BizApp/Production Files/Cut Jobs/" as POSIX file

--Set Complete dest for folder check
--Print Job Folder
set theLineItemPrinterOrderPath to "/Volumes/BizApp/Production Files/Print Jobs/" & varOrderNumber & "-" & varOrderLineItem & "-" & varCompany as POSIX file
--Cut Job Folder
set theLineItemCutterOrderPath to "/Volumes/BizApp/Production Files/Cut Jobs/" & varOrderNumber & "-" & varOrderLineItem & "-" & varCompany as POSIX file

--Here we can turn on some more debugging of our Path
--display dialog "Print Path- " & thePrinterPath & " Cutter Path- " & theCutterPath

--Here we are going to check to make sure that we are suppose to copy the files or not.

tell application "Finder"
	try
		--Check to make sure this part should be transfered.
		if varTrnsfrChk = "y" then
			
			--Here we are going to check to make sure that the part was not marked as no graphic
			if varPrintChk = "False" then
				--Here we will check to see if the folder already Exists
				if not (exists folder theLineItemPrinterOrderPath) then
					display dialog "Doesn't Exist"
					try
						--If not make it.
						set theLineItemPrinterOrderPath to make new folder at thePrintJobsPath with properties {name:varOrderNumber & "-" & varOrderLineItem & "-" & varCompany}
					on error
						--Do Nothing
					end try
				else
					display dialog "The Folder exists"
				end if
				--Here we will attempt to copy the files.
				try
					--first delete anything that may have been there.
					try
						delete (every item of folder theLineItemPrinterOrderPath)
					on error
						--Do Nothing
					end try
					--Now duplicate the files from the Final Files to Print folder to the Job folder.
					duplicate items of folder theFilesForPrint to folder theLineItemPrinterOrderPath with replacing
				on error
					display dialog "There was an issue copying the Final Files for Print. The entire Script will Halt!" buttons {"OK"}
					error number -128
				end try
			else
				display dialog "This part has been selected to have no Print Graphic, Please confirm." buttons {"OK"}
			end if
			
			
			
			--here we are going to check to see if there is a cut file for this job.
			if varCutFile = "true" then
				
				
				--Here we will check to see if the folder already Exists
				if not (exists folder theLineItemCutterOrderPath) then
					try
						--If not make it.
						set theLineItemCutterOrderPath to make new folder at theCutJobsPath with properties {name:varOrderNumber & "-" & varOrderLineItem & "-" & varCompany}
					end try
				end if
				--Here we will attempt to copy the files.
				try
					--first delete anything that may have been there.
					try
						delete (every item of folder theLineItemCutterOrderPath)
					on error
						--Do Nothing
					end try
					--Now duplicate the files from the Cut Files folder to the Job folder.
					duplicate items of folder theCutFiles to folder theLineItemCutterOrderPath with replacing
				on error
					display dialog "There was an issue copying the Final Files for Print. The entire Script will Halt!" buttons {"OK"}
					error number -128
				end try
				
				
			else
				--Do Nothing
			end if
		else
			--Do Nothing
		end if
	end try
end tell






When you use:

               if not (exists folder theLineItemPrinterOrderPath) then

the variable theLineItemPrinterOrderPath needs to be an HFS path string. You have it as a POSIX file. You probably need this:

set theLineItemPrinterOrderPath to "/Volumes/BizApp/Production Files/Print Jobs/" & varOrderNumber & "-" & varOrderLineItem & "-" & varCompany as POSIX file as text