innodes Posted October 13, 2009 Posted October 13, 2009 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
innodes Posted October 13, 2009 Author Posted October 13, 2009 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.
librone Posted October 15, 2009 Posted October 15, 2009 you can use a container field and try to import the file, then capture error 100 if file not exists. Ann
librone Posted October 16, 2009 Posted October 16, 2009 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 :
mweiss Posted October 18, 2009 Posted October 18, 2009 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
mweiss Posted October 18, 2009 Posted October 18, 2009 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.
Recommended Posts
This topic is 5513 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now