Jump to content

how would you validate a file exists?


innodes

This topic is 5327 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 5327 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.