Jump to content
Server Maintenance This Week. ×

Export multiple file references in a portal to a ZIP file ???


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

Recommended Posts

Hi there,

I'm posting this here because I *THINK* it's a job for Applescript but I'm not sure...

I have a portal with file references in it-- between 3-12 file references depending on the record. I'd like to give the user a button that will export all the files that are referenced to one zip file.

Any ideas about how I could pull this off :)

many thanks in advance!

:(

Link to comment
Share on other sites

There are two parts to this:

1) Exporting the files from FileMaker (I assume by 'file references' you mean container fields?).

Use a FileMaker script:

Go to portal row [first]

Loop

   set variable $fileName to "file:" & get(systemdrive) & "TempFolder/" & get(portalRowNumber) & ".doc"

   export field contents [ portalRelationship::container ; $fileName ]

   Go to portal row [next, exit after last]

End loop




This will create files 1.doc, 2.doc, 3.doc etc in "TempFolder" in the root of your startup disk. Modify as you see fit.





2) AppleScript to zip the folder





The following two FileMaker script steps can be used straight after the above. It tends to be easiest to set a variable first, with the contents of the AppleScript, then use another line to call it "whole":




Set variable $AppleScript to "do shell script "ditto -ckv /TempFolder /TempFolder.zip""

Perform AppleScript $AppleScript

We are using a Mac OS X shell command called 'ditto' here, which is what does the zipping. This method is very reliable as it doesn't matter what the Finder or other applications are doing when the script is called, so you are very unlikely to get any errors with it (except for wrong paths etc as you test it).

Hope this helps. I've subscribed to this topic, please let us know how you get on.

James

Link to comment
Share on other sites

James I'm wondering a little about your technique here, you are writing to the temp directory, but other files might very well exist in it from other applications use at least, aren't you urged to create a folder as well before attempting to zip it, or use the knowledge as to which of the files to include, via some sort of piping?

--sd

Link to comment
Share on other sites

Oh absolutely, you should add extra code to make sure that you are using a unique folder, check the folder is empty when you start, check it exists or create it if it doesn't, check you don't overwrite one zip file with the previous one etc etc.

The purpose of my examples was to get you up and going and have a place from which to start testing and exploring...

James

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for your help guys.. is "tempfolder" a folder I would create in the root?

I tried to do the filemaker script part of it, and it saved the files to the application folder of FileMaker 10 Advanced.

I tried to create a "Tempfolder" in the root of the hard drive and that didn't help.

Edited by Guest
Link to comment
Share on other sites

is "tempfolder" a folder I would create in the root?

This is what the Get(systemdrive) suggests, but if it really should be embraced is another matter, I would instead use the OS temp directory instead, where I then ahead of the munging would delete the previous of the same name and then create the required folder again to make sure it's empty.

I would prevent cluttering the root with unnecessary junk by all means to prevent wasting time on re-indexing - not that it matters much with todays OS'es but it used to matter!

--sd

Link to comment
Share on other sites

There are a few "temp" folders. If you're using FileMaker 10, its Get (TemporaryFolder) is good.* AppleScript also knows a couple other good ones. For security, Leopard adds some changing text to the higher level one, so it's more difficult to target. The user one is already secure, as no one knows your user name.

set tmp_system to path to temporary items as text

-- "Macintosh HD:private:var:folders:UD:UDdmAXvGGA8BuatQgyGdpE+++TI:TemporaryItems:"

set tmp_user to path to temporary items from user domain as text

-- "Macintosh HD:Users:shortusername:Library:Caches:TemporaryItems:"

I would say that the last one is the most user-friendly. Interestingly, that folder may not exist if you go now to look for it. But running an AppleScript targeting it (such as the above) will create the folder. Don't then delete the folder, or you'll have to Restart and run the AppleScript again to get it back (I had to know how it worked :-).

*FileMaker 9 also has Get (TemporaryFolder), but it did not seem to delete items in it, so I did not want to use it, especially since AppleScript knows its own. But FileMaker 10 fixed that, slightly different location.

Link to comment
Share on other sites

Fenton your reply seems to me somewhat disjoint from the threads use of:

ditto -ckv

...under shellscript, it not really a matter of where to send data to but merely a question where to make a new folder, then put something in it and finally make an archive file with the content.

The issue is no how to make folders but, to be sure nothing irrelevant finds it's way into this new folder, and the folder to archive leaves no choice what so ever, older ones should be ignored to say the least, but getting rid of them could perhaps be useful?

--sd

Link to comment
Share on other sites

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