Jump to content
Salesforce and other SMB Solutions are coming soon. ×

image rename


Guest

Recommended Posts

Hi All,

 

Pretty new to filemaker so reallly would appreciate some help.

 

The problem is I need to make a calcualtion field that copies the image name from the image name field, strips out the ".tif" or ".eps" file extension and adds ".jpg"

instead.

 

Any help very very much appreciated.

 

Simon

Link to comment
Share on other sites

Hi Simon,

There are a variety ways to approach this, depending on the range of formats of the existing data and the way you wish to go about performing the update.

 

The following script, for example, will re-format the filenames in the current found set, replacing the original names with the revised ones:

 

Go To Record/Request/Page [First]

Loop

Set Field ["image name", "Left(image name & ".", Position(image name & ".", ".", 1, 1) - 1) & ".jpg" "]

Go To Record/Request/Page [Exit after last, Next]

End Loop

Go To Record/Request/Page [First]

 

This particular construct will deal with extensions of different lengths (or no extension at all), but works on the assumption that the file names themselves (ie prior to the extension) do not include any additional dot characters - as the extension is identified as everything after the first dot.

 

An alternative construct for the set field calc expression would be:

 

Set Field ["image name", "Left(image name, Length(image name) - 3) & "jpg" "]

 

- which presumes that all the image names have extensions and that all the extensions are three characters in length. It's a simple but 'blunt' instrument.

 

If you want the image name to appear in a different field, you can use the same kind of scrfipt, but simply target the Set Field [ ] command elsewhere - eg:

 

Set Field ["new image name", "Left(image name, Length(image name) - 3) & "jpg" "]

 

Hopefully the above will give you a few ideas to work with. wink.gif

Link to comment
Share on other sites

Thanks Ray.

 

Are these bothy scripts though?

 

Or will the work on a cacluation field.

 

At the moment I've got this:

 

"smallpath/" & imagename

 

which actually looks like:

 

smallpath/simon.tif

 

which simply creates the path to my lo res files.

 

If the extension is .tif can I replace with .jpg.

 

Thanks Again

 

Simon

Link to comment
Share on other sites

hi simon ...

 

Ray gave you examples of script steps for looping through your records to change the extension of the filepath. The "SetField" steps include formulae that you can also use in calculations.

 

For instance, create a calculation field of type Text (let's call it "new image name"), and enter the formula from Ray's first SetField example:

 

Left(image name & ".", Position(image name & ".", ".", 1, 1) - 1) & ".jpg"

 

If the current image name is: "smallpath/trees.tif"

 

then "new image name" will return: "smallpath/trees.jpg"

 

if there is only one "." character in all of your image names.

 

Ray's alternate SetField formula deals with situations where the image name might contain more than one "." character, and it also assumes that the current image name extension is exactly 3 characters. In this case, you can create a calculation of type Text, and enter the following

 

Left(image name, Length(image name) - 3) & "jpg"

 

You could also use combinations of the above with the Case and PatternCount functions. For example:

 

Case(

 

PatternCount(image name, ".") = 1, Left(image name & ".", Position(image name & ".", ".", 1, 1) - 1) & ".jpg",

 

Left(image name, Length(image name) - 3) & "jpg"

 

)

 

This will use Ray's first formula if the image name contains only one "." character. In all other situations, it will use Ray's second formula.

 

If you are sure that none of your image names contain more than one "." character, and that the extensions are all ".tif" or ".eps", then you could use the following in either a SetField step or in a calculation field:

 

Substitute(Substitute(image name, ".tif", ".jpg"), ".eps", ".jpg")

 

If there are more possible image name extensions, e.g., ".bmp" or ".tiff", you can add Substitution functions to the above like:

 

Substitute(Substitute(Substitute(Substitute(image name, ".tif", ".jpg"), ".eps", ".jpg"), ".bmp", ".jpg"), ".tiff", ".jpg")

 

Hope this helps, and good luck!

Link to comment
Share on other sites

THanks Jim,

 

Substitute(Substitute(image name, ".tif", ".jpg"), ".eps", ".jpg")

 

This one did the trick perfectly.

 

Thanks Ray Aswell.

 

Simon

Link to comment
Share on other sites



×
×
  • Create New...

Important Information

Terms of Use