October 13, 200916 yr I am going to import a file from a folder on the users desktop. The scripts are in place to do so and working. I want to add a safety step that verifies that the file exists before continuing in the script. The only way I could figure do to this is to use Send Event and Applescript and to rename the file to itself. It will not harm the file, and should create an error message if it doesn't exist. Then using Error Capture, I get the determination whether the file exists. I can get it coded to rename the file, from test.tst to test2.txt and back, Send Event [ "cmd /c rename " & Quote ( GLOBALS::x_desktop_g & GLOBALS::x_desktopFolder_g ) & "" & "test.txt" & " " & "test2.txt" ] . . . but when I try the logic looking for a file that is not there (ie. test3.txt), it fails. It shows no error message. There must be a better way than this. Anyone have any suggestions? thanks
October 13, 200916 yr Author From doing some additional digging the following thread was similar. http://fmforums.com/forum/showtopic.php?tid/183715/post/236411/hl/%22validate+file%22/fromsearch/1/#236411 The FMP10 Bible (pg.711) suggests building the vbs within a variable to save out and run. I'm looking into that one also. So I guess I will be trying to learn a bit of visual basic to do this check. If anyone has any better suggestions they would be welcome.
October 15, 200916 yr you can use a container field and try to import the file, then capture error 100 if file not exists. Ann
October 16, 200916 yr I am sorry, I gave you incorrect information. I don't speak English and web traslations are no good. This is the trick for your script. Set Error Capture [ On ] Set Variable [ $file; Value:"filewin:" & Get ( DesktopPath )& "namefolder" & settings::globaltextnamefilewithextension ] Import Records [ Source:“$file”; Method:Update existing; Character Set:“Windows ANSI”] [ No dialog ] [color:red]target:unknown If [ Get ( LastError ) = 100 ] Show Custom Dialog [ Title: "verify"; Message: "file not exsists"; Buttons: “OK” ] End If Ann :
October 18, 200916 yr Here's another way to do it. A set of calculation fields determines what kind of "stuff" is in the container -- whether it stores an embedded object or just a reference, the prefix type (for reference files) and filepath, etc. Then a script executes an Applescript command to check for the existence of the file. In this example the script is triggered any time the record loads or the container field is modified; it can also be executed directly by a button click. This demo also shows how to pass parameters from FMP into Applescript, and how to pass results back again. Check_for_Containers.fp7.zip
October 18, 200916 yr Oh, and ignore that extra "Applescript" table (the one that has no records) in the demo file I just uploaded. It was left over from an earlier version; I forgot to delete it before uploading.
Create an account or sign in to comment