Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

how would you validate a file exists?

Featured Replies

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

  • 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.

you can use a container field and try to import the file, then capture error 100 if file not exists.

Ann

  • Author

thanks

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 :

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.