Trailing slash in path is sometimes missing with imported stacks

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Trailing slash in path is sometimes missing with imported stacks

Stein Rørvik
Thank you Wayne for the quick fix of the wrong image title with forward slashes issue!

Here is another issue related to the Image Sequence command:

There are two ways an image sequence folder can be imported in a macro;
either by specifying the path name or by specifying the path to the first file.
The resulting stack is the same.

However, the getDirectory function returns a path name without the trailing slash in the latter case.
getDirectory is also missing the trailing slash if the stack was opened from a path without it.
One would expect the getDirectory function to always include a trailing slash.
Then one can construct a fully qualified filepath using simply dir + name.
I am not sure of this is a Windows only issue or not since I only have Windows PCs.

This behaviour is the same with both real and virtual stacks, and with single forward or double backslashes.
It does not occur if the stack was imported via the GUI.

Here is a macro demonstrating this issue:
Case B is correct, while I think case A and C is incorrect.

print("\\Clear");
run("Close All");
dir = getDirectory("temp");
dir = replace(dir, "\\", "/");          //use forward slashes

//create a sample tiff virtual stack
run("T1 Head (2.4M, 16-bits)");
File.makeDirectory(dir + "t1-head/");
run("Image Sequence... ", "format=TIFF save="+ dir + "t1-head/");
close();

//import the same stack using three different valid syntaxes

print("A:");
run("Image Sequence...", "open=["+ dir + "t1-head] sort");
OutPath = getDirectory("image");
print("OutPath: " + OutPath);
//the path is now missing the trailing slash

print("B:");
run("Image Sequence...", "open=["+ dir + "t1-head/] sort");
OutPath = getDirectory("image");
print("OutPath: " + OutPath);
//the path now has a trailing slash

print("C:");
run("Image Sequence...", "open=["+ dir + "t1-head/t1-head0000.tif] sort");
OutPath = getDirectory("image");
print("OutPath: " + OutPath);
//the path is now missing the trailing slash

I am using daily build ImageJ 1.52f on Windows 7 64-bit.


Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Trailing slash in path is sometimes missing with imported stacks

Wayne Rasband-2
> On Aug 20, 2018, at 1:46 PM, Stein Rørvik <[hidden email]> wrote:
>
> Thank you Wayne for the quick fix of the wrong image title with forward slashes issue!
>
> Here is another issue related to the Image Sequence command:
>
> There are two ways an image sequence folder can be imported in a macro;
> either by specifying the path name or by specifying the path to the first file.
> The resulting stack is the same.
>
> However, the getDirectory function returns a path name without the trailing slash in the latter case.
> getDirectory is also missing the trailing slash if the stack was opened from a path without it.
> One would expect the getDirectory function to always include a trailing slash.

In the latest ImageJ daily build (1.52f33), the getDirectory("image”) macro function adds a trailing slash if it is missing.

-wayne

> Then one can construct a fully qualified filepath using simply dir + name.
> I am not sure of this is a Windows only issue or not since I only have Windows PCs.
>
> This behaviour is the same with both real and virtual stacks, and with single forward or double backslashes.
> It does not occur if the stack was imported via the GUI.
>
> Here is a macro demonstrating this issue:
> Case B is correct, while I think case A and C is incorrect.
>
> print("\\Clear");
> run("Close All");
> dir = getDirectory("temp");
> dir = replace(dir, "\\", "/");          //use forward slashes
>
> //create a sample tiff virtual stack
> run("T1 Head (2.4M, 16-bits)");
> File.makeDirectory(dir + "t1-head/");
> run("Image Sequence... ", "format=TIFF save="+ dir + "t1-head/");
> close();
>
> //import the same stack using three different valid syntaxes
>
> print("A:");
> run("Image Sequence...", "open=["+ dir + "t1-head] sort");
> OutPath = getDirectory("image");
> print("OutPath: " + OutPath);
> //the path is now missing the trailing slash
>
> print("B:");
> run("Image Sequence...", "open=["+ dir + "t1-head/] sort");
> OutPath = getDirectory("image");
> print("OutPath: " + OutPath);
> //the path now has a trailing slash
>
> print("C:");
> run("Image Sequence...", "open=["+ dir + "t1-head/t1-head0000.tif] sort");
> OutPath = getDirectory("image");
> print("OutPath: " + OutPath);
> //the path is now missing the trailing slash
>
> I am using daily build ImageJ 1.52f on Windows 7 64-bit.
>
>
> Stein
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Trailing slash in path is sometimes missing with imported stacks

Stein Rørvik
Thanks, works fine!

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 21. august 2018 03:37
To: [hidden email]
Subject: Re: Trailing slash in path is sometimes missing with imported stacks

> On Aug 20, 2018, at 1:46 PM, Stein Rørvik <[hidden email]> wrote:
>
> Thank you Wayne for the quick fix of the wrong image title with forward slashes issue!
>
> Here is another issue related to the Image Sequence command:
>
> There are two ways an image sequence folder can be imported in a
> macro; either by specifying the path name or by specifying the path to the first file.
> The resulting stack is the same.
>
> However, the getDirectory function returns a path name without the trailing slash in the latter case.
> getDirectory is also missing the trailing slash if the stack was opened from a path without it.
> One would expect the getDirectory function to always include a trailing slash.

In the latest ImageJ daily build (1.52f33), the getDirectory("image”) macro function adds a trailing slash if it is missing.

-wayne

> Then one can construct a fully qualified filepath using simply dir + name.
> I am not sure of this is a Windows only issue or not since I only have Windows PCs.
>
> This behaviour is the same with both real and virtual stacks, and with single forward or double backslashes.
> It does not occur if the stack was imported via the GUI.
>
> Here is a macro demonstrating this issue:
> Case B is correct, while I think case A and C is incorrect.
>
> print("\\Clear");
> run("Close All");
> dir = getDirectory("temp");
> dir = replace(dir, "\\", "/");          //use forward slashes
>
> //create a sample tiff virtual stack
> run("T1 Head (2.4M, 16-bits)");
> File.makeDirectory(dir + "t1-head/");
> run("Image Sequence... ", "format=TIFF save="+ dir + "t1-head/");
> close();
>
> //import the same stack using three different valid syntaxes
>
> print("A:");
> run("Image Sequence...", "open=["+ dir + "t1-head] sort"); OutPath =
> getDirectory("image");
> print("OutPath: " + OutPath);
> //the path is now missing the trailing slash
>
> print("B:");
> run("Image Sequence...", "open=["+ dir + "t1-head/] sort"); OutPath =
> getDirectory("image");
> print("OutPath: " + OutPath);
> //the path now has a trailing slash
>
> print("C:");
> run("Image Sequence...", "open=["+ dir + "t1-head/t1-head0000.tif]
> sort"); OutPath = getDirectory("image");
> print("OutPath: " + OutPath);
> //the path is now missing the trailing slash
>
> I am using daily build ImageJ 1.52f on Windows 7 64-bit.
>
>
> Stein
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html