Jump to content

  •  

Photo

Verifying if folder/file exists


  • Please log in to reply
17 replies to this topic

#1 Rafita  enthusiast

Rafita
  • Members
  • 54 posts
  • FM Application:8 Advance
  • :

Posted 29 September 2008 - 08:53 AM

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.
  • 0
Rafael A. Alvarado
Without counsel purposes are disappointed; but in the multitude of counsellors they are established.
Proverbs 15:22

#2 mr_vodka  Candy is Dandy... But Liquor is Quicker

mr_vodka
  • Moderators
  • 5,917 posts
  • LocationOld Bridge, NJ
  • FM Application:12 Advance
  • FMGo:iPad
  • Platform:Windows XP
  • Skill Level:Expert
  • Certification:8, 9, 10, 11
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 9d 7h 4m 12s

Posted 29 September 2008 - 10:11 AM

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
  • 0
- John Ahn
Life3D Studios
FMfunctions.com, Co-founder

#3 Rafita  enthusiast

Rafita
  • Members
  • 54 posts
  • FM Application:8 Advance
  • :

Posted 30 September 2008 - 09:02 AM

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.
  • 0
Rafael A. Alvarado
Without counsel purposes are disappointed; but in the multitude of counsellors they are established.
Proverbs 15:22

#4 Fenton  Post Master General

Fenton
  • Moderators
  • 5,046 posts
  • FM Application:11 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Expert
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 17h 12m 20s

Posted 30 September 2008 - 10:19 AM

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

#5 Miko  enthusiast

Miko
  • Members
  • 38 posts
  • FM Application:9 Advance
  • :

Posted 03 November 2008 - 08:27 AM

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

#6 Fenton  Post Master General

Fenton
  • Moderators
  • 5,046 posts
  • FM Application:11 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Expert
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 17h 12m 20s

Posted 03 November 2008 - 09:46 AM

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

#7 Miko  enthusiast

Miko
  • Members
  • 38 posts
  • FM Application:9 Advance
  • :

Posted 03 November 2008 - 10:30 AM

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?
  • 0

#8 Miko  enthusiast

Miko
  • Members
  • 38 posts
  • FM Application:9 Advance
  • :

Posted 03 November 2008 - 10:54 AM

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

#9 NovaChan  novice

NovaChan
  • Members
  • 56 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Expert
  • Certification:9, 10, 11, 12
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1d 22h 39m 41s

Posted 14 January 2009 - 12:23 PM

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

#10 sprynmd  novice

sprynmd
  • Members
  • 18 posts
  • FM Application:10 Advance
  • :

Posted 28 August 2009 - 09:43 AM

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

#11 NovaChan  novice

NovaChan
  • Members
  • 56 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Expert
  • Certification:9, 10, 11, 12
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1d 22h 39m 41s

Posted 28 August 2009 - 11:15 AM

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!
  • 0

#12 sprynmd  novice

sprynmd
  • Members
  • 18 posts
  • FM Application:10 Advance
  • :

Posted 31 August 2009 - 12:15 PM

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

#13 NovaChan  novice

NovaChan
  • Members
  • 56 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Expert
  • Certification:9, 10, 11, 12
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1d 22h 39m 41s

Posted 31 August 2009 - 12:29 PM

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

#14 sprynmd  novice

sprynmd
  • Members
  • 18 posts
  • FM Application:10 Advance
  • :

Posted 01 September 2009 - 04:42 AM

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

#15 NovaChan  novice

NovaChan
  • Members
  • 56 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Expert
  • Certification:9, 10, 11, 12
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1d 22h 39m 41s

Posted 03 September 2009 - 07:01 AM

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 ;)
  • 0

#16 NovaChan  novice

NovaChan
  • Members
  • 56 posts
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Expert
  • Certification:9, 10, 11, 12
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1d 22h 39m 41s

Posted 03 September 2009 - 07:37 AM

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

#17 sprynmd  novice

sprynmd
  • Members
  • 18 posts
  • FM Application:10 Advance
  • :

Posted 17 September 2009 - 06:18 AM

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

#18 MParker  enthusiast

MParker
  • Members
  • 73 posts
  • FM Application:11 Advance
  • Platform:Mac OS X Mavericks
  • Skill Level:Intermediate
  • Time Online: 3h 58m 39s

Posted 26 July 2013 - 01:31 PM

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.


  • 0




FMForum Advertisers