如何使用Script-Fu解析基本文件名 [英] How to parse out base file name using Script-Fu

查看:163
本文介绍了如何使用Script-Fu解析基本文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用从gimp.org下载的用于Mac OS X(在X11下)的Gimp 2.6.6.

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

我正在尝试使用Script-Fu自动执行无聊的手动过程.我需要解析图像文件名,以使用原始文件名的后缀将各层保存为新文件.

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.

我最初的尝试是这样的,但是失败了,因为(string-search ...)在2.6下似乎不可用(对脚本引擎进行了更改?).

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

然后我尝试使用此信息以使用正则表达式解析出基本文件名,但也无法识别(re-match-nth ...).

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

虽然将值从向量中拉出时没有错误,但将结果值传递给(string-append ...)时,该结果值不视为字符串.

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?

推荐答案

上下文

GIMP 2.6.6 Windows Vista SP2

Context

GIMP 2.6.6 Windows Vista SP2

提取原始文件名的基础名称,不扩展其名称.

Extract the basename of the original filename without its extension.

错误:eval:未绑定变量: re-match-nth

Error: eval: unbound variable: re-match-nth

可能的建议

GIMP菜单"过滤器">"脚本功能">"控制台"

Possible suggestion

GIMP menu "Filters" > "Script-Fu" > "Console"

在输入框中,粘贴以下Script-Fu函数定义 然后按 ENTER 键:

In the input box, paste the following Script-Fu definition of function then hit the ENTER key:

(define (filename-basename orig-name)
    (car (strbreakup orig-name "."))
    ; Nimmzo 09/09/30: the string split function strbreakup is defined 
    ; in the compatibility file from SIOD to TinyScheme:
    ; C:\Program Files\GIMP\share\gimp\2.0\scripts\script-fu-compat.init
) ; end  filename-basename

要测试功能,请输入:

(filename-basename "screen.xcf")

Script-Fu控制台回答:

The Script-Fu Console answers:

"screen"

这篇关于如何使用Script-Fu解析基本文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆