Paste: paths and extension bumping
Author: | rien |
Mode: | factor |
Date: | Sun, 11 Dec 2011 07:55:56 |
Plain Text |
IN: scratchpad \ path-without-extension see
USING: kernel sequences ;
IN: scratchpad
: path-without-extension ( path -- path )
[ [ 46 = ] find-last drop ] keep swap head ;
IN: scratchpad \ bump-ext see
USING: io.pathnames kernel math math.parser sequences ;
IN: scratchpad
: bump-ext ( path -- path )
dup file-extension string>number [
[ path-without-extension "." ] dip 1 +
number>string 3append
] [ ".1" append ] if* ;
IN: scratchpad "/Users/username/Desktop/dummy.txt" bump-ext
--- Data stack:
"/Users/username/Desktop/dummy.txt.1"
IN: scratchpad bump-ext
--- Data stack:
"/Users/username/Desktop/dummy.txt.2"
IN: scratchpad bump-ext .
"/Users/username/Desktop/dummy.txt.3"
IN: scratchpad "/Users/username/Desktop/dummy" bump-ext
--- Data stack:
"/Users/username/Desktop/dummy.1"
IN: scratchpad bump-ext .
"/Users/username/Desktop/dummy.2"
Author: | rien |
Mode: | factor |
Date: | Sun, 11 Dec 2011 07:56:45 |
Plain Text |
USING: io.pathnames kernel math math.parser sequences ;
: path-without-extension ( path -- path )
[ [ 46 = ] find-last drop ] keep swap head ;
: bump-ext ( path -- path )
dup file-extension string>number [
[ path-without-extension "." ] dip 1 +
number>string 3append
] [ ".1" append ] if* ;
New Annotation