MACRO Language | maybe useful RegEx-Example (Top Directory, one level up)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

MACRO Language | maybe useful RegEx-Example (Top Directory, one level up)

Rainer M. Engel
Hey there,

I recently wanted to create folders and files in the top directory
relative to the one defined in "getDirectory" dialogue.

By this, one gets no altering in a source folder and secondly I wanted
to test RegularExpressions a bit.



dir1   = getDirectory("SourceImages Directory");
list1 = getFileList(dir1);
//get top directory i.e. one level up
topDir = replace(dir1, "([a-zA-Z0-9_]*)\\\\$", "");



Perhaps useful here and there..
Rainer

--
Rainer M. Engel, Dipl. Digital Artist
scientific|Media GbR
Pichelsdorferstr. 143
D-13595 Berlin
Reply | Threaded
Open this post in threaded view
|

Re: MACRO Language | maybe useful RegEx-Example (Top Directory, one level up)

Gabriel Landini
On Monday 16 Jan 2012 17:31:01 you wrote:

> I recently wanted to create folders and files in the top directory
> relative to the one defined in "getDirectory" dialogue.
>
> By this, one gets no altering in a source folder and secondly I wanted
> to test RegularExpressions a bit.
>
> dir1   = getDirectory("SourceImages Directory");
> list1 = getFileList(dir1);
> //get top directory i.e. one level up
> topDir = replace(dir1, "([a-zA-Z0-9_]*)\\\\$", "");

Does not work under linux...
dir1 and topDir are the same.

I think the last line needs to be:

topDir  = replace(dir1, "([a-zA-Z0-9_]*)\\"+File.separator+"\$", "");

note the File.separator for the differences between windows and unix (not sure
what macs use).

But this does not work either for folder names like "image.src.etc", so maybe
one also needs to include the "." or "\." ? Not sure which one.

Cheers
Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: MACRO Language | maybe useful RegEx-Example (Top Directory, one level up)

Rainer M. Engel
Am 16.01.2012 21:13, schrieb Gabriel Landini:
> Does not work under linux...
> dir1 and topDir are the same.

Too bad.. I forgot about that. But on Windows it worked like expected. I
tried that, but I'm not sure if the escaping of characters is the only
difference on other architectures then.

Any last Folder-Name containing alpha-numeric characters plus
underscore, dash and points (in pendent from their frequency of
appearance).

On Windows these three lines do work:
topDir=replace(dir1,
"([a-zA-Z0-9_.-]+)"+File.separator+File.separator+"$", "");

topDir=replace(dir1, "([a-zA-Z0-9_.-]+)\\"+File.separator+"$", "");

topDir=replace(dir1, "([a-zA-Z0-9_.-]+)\\\\$", "");


Regards,
Rainer


--
Rainer M. Engel, Dipl. Digital Artist
scientific|Media GbR
Pichelsdorferstr. 143
D-13595 Berlin
Reply | Threaded
Open this post in threaded view
|

Re: MACRO Language | maybe useful RegEx-Example (Top Directory, one level up)

Gabriel Landini
On Monday 16 Jan 2012 21:17:48 you wrote:
 
> topDir=replace(dir1, "([a-zA-Z0-9_.-]+)\\"+File.separator+"$", "");
Yes that seems to work in linux, and so does this:
topDir=replace(dir1, "([a-zA-Z0-9_.-]+)"+File.separator+"$", "");

Cheers
Gabriel