Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse out base file name using Script-Fu

Tags:

People also ask

How do I get only the filename in PowerShell?

Use the GetFileName Method to Extract the Filename From a Path in PowerShell. The GetFileName method of the . NET's Path class returns the file name and extension of the specified path.

What is Script Fu in gimp?

Script-Fu is a language for writing scripts, which allow you to run a series of GIMP commands automatically.

How do I strip a file extension in Python?

To remove the extension from a filename using Python, the easiest way is with the os module path. basename() and path. splitext() functions. You can also use the pathlib module and Path and then access the attribute 'stem' to remove the extension from a filename.

Is filename one word or two?

The original form of the word was "file name" and "filename" became popular as more people and software programs began to use that version of the word. According to the Microsoft Manual of Style, a file name is "Two words both as an adjective and as a noun when referring to the name of a file. Do not hyphenate."


Using Gimp 2.6.6 for MAC OS X (under X11) as downloaded from gimp.org.

I'm trying to automate a boring manual process with Script-Fu. I needed to parse the image file name to save off various layers as new files using a suffix on the original file name.

My original attempts went like this but failed because (string-search ...) doesn't seem to be available under 2.6 (a change to the scripting engine?).

(set! basefilename (substring filename 0 (string-search "." filename))) 

Then I tried to use this information to parse out the base file name using regex but (re-match-nth ...) is not recognized either.

(if (re-match "^(.*)[.]([^.]+)$" filename buffer)
    (set! basefilename (re-match-nth orig-name buffer 1))
    )

And while pulling the value out of the vector ran without error, the resulting value is not considered a string when it is passed into (string-append ...).

(if (re-match "^(.*)[.]([^.]+)$" filename buffer)
    (set! basefilename (vector-ref buffer 1))
    ) 

So I guess my question is, how would I parse out the base file name?