Sign in to follow this  
Followers 0

Verifying if folder/file exists

18 posts in this topic

Posted

Hi!

I'm in the Importing process of a database.

In order to verify if the source file exists in the desktop -before "Delete all" script in the destination file-,I tried the "not IsValid ( $desktop ), where $desktop stands for

Set Variable [Let ( [

MAC = "filemac:" & Get ( DesktopPath ) ;

PC = "filewin:" & Get ( DesktopPath )

] ;

Case(Abs(Get ( SystemPlatform )) = 1; MAC; Abs(Get ( SystemPlatform )) = 2 ;

PC ) & "MainDatabase/" & Get ( FileName ))

I think that the IsValid step doesn't work here, because it is ignored in the process. Does somebody know if there is any other step to verify in advance if the file or folder exists in the desktop?

Tks.

Share this post


Link to post
Share on other sites

Posted

Take a look at this free plugin written by one of our forums members.

Mooplug

You can actually do it without using plugin by running a shell script / batch script but the plugin is just easier. :P

Share this post


Link to post
Share on other sites

Posted

Well, the plug-in looks good for the purpose, but I like to leave plug-ins as a last resource. ¿Don't you think that I could play maybe with the import step, as it warns if it doesn't find the file?

Tnx.

Share this post


Link to post
Share on other sites

Posted

You can import the file path, [x] Reference only, into a global container field. Trap for error.

Share this post


Link to post
Share on other sites

Posted

how do you trap for the error. cause currently, my script attempts to copy a file from a server to the desktop using a global container to hold the path. if it doesn't locate it, a window pops up asking for it to be located. the only error i seem to be able to trap is the one canceling the locate dialog. i too am stumped with how to script it to detect a missing file that was originally placed in a container but has been moved or deleted.

thanks,

Limore

Share this post


Link to post
Share on other sites

Posted

Well, so much for my advice :-[ Actually I remember now that it is a method to establish the default dialog path and [x] As reference toggle. So, good for something, but not for what you need.

If it was only on a Mac, I'd fall back on FileMaker's Perform AppleScript script step. An AppleScript error can be captured by FileMaker's Set Error Capture ["On"]. If you have the Mac syntax filepath (with the colons)* then the simplest test for a file is (example file):

alias "Macintosh HD:Users:fej:Desktop:donuts.pdf"

That will produce an error if the file does not exist there, which you can catch in FileMaker. You would have to pass the Mac syntax path into the Perform AppleScript step, by getting it from a field (cell) on the current record, on the current layout (hopefully, though you could also specify a layout where it was, though Insert requires the container field on the layout).

* It is pretty easy to convert between an AppleScript path and a FileMaker syntax path. There is also the Get functions like Get (DesktopPath).

Share this post


Link to post
Share on other sites

Posted

do you know how the syntax would be if you were to use a calculated applescript which dynamically set the file path to a field on the layout?

Share this post


Link to post
Share on other sites

Posted

replying to myself. gotta love that.

here is the applescript syntax for anyone interested in a calculated applescript to test whether a file exists or not.

"set thePath to "" & YourTable::FilePath & """ & ¶ &

"alias thePath"

you must convert the filepath to something that applescript understands. Like:

VolumeName:FolderName:FileName.pdf

and this can be done with a calculation easily enough.

then setting error capture on, trap for -43 which is the applescript error for a file not found.

enjoy.

Share this post


Link to post
Share on other sites

Posted

This post is late and just for the record. There is a native method that will work on files, though I'm unsure about folders.

The "Import Records" script step does not show any dialogs if you are capturing errors. Just set the import to "update existing records" and only point to an unimportant global field. Error 100 is returned if the file is missing.

If you're looking for a specific folder, you're probably out of luck unless you know the name of a file it contains.

Share this post


Link to post
Share on other sites

Posted

This approach almost worked for me.

But, if the file I'm checking is a .xls file with multiple worksheets, FileMaker pops up a dialog box asking the user to select a worksheet. I haven't found a way to intercept the dialog box.

...Mike

Share this post


Link to post
Share on other sites

Posted

Thanks for the observation sprynmd. I don't see any way around that prompt either. It would be nice if we could specify a worksheet in the file path, but I don't think that's possible.

It is possible to limit the file type to one type like fp7 in the import setup dialog. In that case, invalid files still result in an error dialog, so invalid extensions would have to be handled before the import step. Of course, this doesn't help you.

Please post back if you find a good solution!

Share this post


Link to post
Share on other sites

Posted

I was finally able to do what I want using an approach in a different thread:

Post# 202706

Using the insert command seems to do the trick for me. Because my system is multi-platform, I had to have 3 file paths on the insert command (the file to be inspected, a known Mac file, and a known PC file). The one thing which tripped me up initially was that the global container had to exist on the current layout. Once I got around that, my file-exists check seems to work fine.

I also tried 360Works ScriptMaster free plugin check file, but it only seems to work in the primary disk volume. My files are on a server.

...Mike

Share this post


Link to post
Share on other sites

Posted

Thanks for following up Mike. I like it when the solution is simple, native and clever ;)

I haven't used the feature, but it sounds odd that the SriptMaster pluging would only work with the Documents folder. I'm sure someone at 360Works will clarify the details with you via email if you ever need to revisit that approach.

Share this post


Link to post
Share on other sites

Posted

Sorry, NovaChan. I edited my note shortly after posting.

360Works seems to see only the primary disk volume (not just the documents folder). But, I need to see a server volume. I posted a question on that issue in the ScriptMaster forum but have not yet received a response.

One more disadvantage of the insert approach to checking file existence is that a large file will take time to insert. All I want is to know that it's there. This is especially frustrating if I'm looping through several records checking files.

...Mike

Share this post


Link to post
Share on other sites

Posted

Mike,

Did you try importing the file as a reference only? I just realized that Fenton actually suggested this technique back at the beginning of this thread. Seems the discussion could have ended there for all our progress ;)

Share this post


Link to post
Share on other sites

Posted

Rafael, your question was just sent to my inbox again, so I thought I'd touch back on it.

If you're manually supervising an import process with multiple tables, it's often easiest to open the source file beforehand (esp if it's password protected). In this case your script can set error capture [On], open the file [hidden], then trap for errors.

Share this post


Link to post
Share on other sites

Posted

NovaChan:

Thanks for the suggestion. Yes, I tried insert by reference. The content of the container requires some additional text-processing because more than just the file name is inserted in the container. Some initial tests seem to show that by-reference does not make a difference on timing. But, it's working now in direct (non-reference) mode and other priorities prevent me from experimenting any more at this time.

Thanks again for the input!

...Mike

Share this post


Link to post
Share on other sites

Posted

replying to myself. gotta love that.

here is the applescript syntax for anyone interested in a calculated applescript to test whether a file exists or not.

"set thePath to "" & YourTable::FilePath & """ & ¶ &

"alias thePath"

you must convert the filepath to something that applescript understands. Like:

VolumeName:FolderName:FileName.pdf

and this can be done with a calculation easily enough.

then setting error capture on, trap for -43 which is the applescript error for a file not found.

enjoy.

 

i know this is a really old post, and i'm terribly sorry for bumping it, but i just wanted to say thank you so much....you just saved my a$$ with that.  big time.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0