Jump to content
Server Maintenance This Week. ×

Verifying if folder/file exists


Rafita

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

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 months later...

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.

Link to comment
Share on other sites

  • 7 months later...

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

  • 3 years later...

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.

Link to comment
Share on other sites

  • 5 years later...
  • Newbies

Anyone know how to install MooPlug into FIleMaker 16 Pro Advanced 64bit?  I placed the .fmx file into the extentions folder under AppData/.../...  but it is not showing in the Preferences Dialog Window under the Plugin tab?

Edited by Costa Zachariou
Typo error
Link to comment
Share on other sites

This thread started in 2008. MooPlug hasn't been updated since 2010. It's now 2018.

I wouldn't assume it even works with FM16.

@Costa, you didn't say what your goal is, but if you want a great supported free plugin, try:

http://www.goya.com.au/baseelements-plugin/

 

Link to comment
Share on other sites

This topic is 2038 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.