Please help: Creating a directory and saving files automatically

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

Please help: Creating a directory and saving files automatically

LyleBabcock
Creating a directory and saving files in it seems really easy from all the
tutorials and everything, but in practice it seems absolutely impossible.
Whenever I am able to get a directory folder titled "Results", the files are
never saved there, either not saved at all, or saved in the same file as the
directory, just not the directory itself. I'm simply trying to create a
directory titled "Results", and I want to save image and text files in it.
Can someone please help me out with a code that will do this?

Thank you.



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Please help: Creating a directory and saving files automatically

Herbie
Good day Lyle,

from what you write I see that you are quite desperate:
"[...] but in practice it seems absolutely impossible."

Attached please find an ImageJ demo macro (as a ZIP-file) that shows that
what you want, is indeed possible.
demo.zip <http://imagej.1557.x6.nabble.com/file/t380516/demo.zip>  

// imagej-macro "saveDemo" (Herbie G., 12. Oct. 2019)
requires("1.52q");
msg="This demo macro needs an open internet connection.\n"+
"It saves the 'blob'-image to and creates a 'results'-folder in the home
directory.\n"+
"It finally saves the processed image and the Results table to the
'results'-folder.";
showMessage(msg);
run("Blobs (25K)");
img=getTitle();
// save the downloaded image to the home directory
homePath=getDirectory("home");
saveAs("tif", homePath+img);
// create the results folder in the home directory
resultsPath=homePath+"ResultsFolder";
File.makeDirectory(resultsPath);
// process image
run("Set Measurements...", "area centroid perimeter redirect=None
decimal=3");
setOption("BlackBackground", true);
run("Invert");
setAutoThreshold("Default dark");
run("Analyze Particles...", "  show=Nothing display exclude");
// save processed image and Results table to the results folder
img=split(img, ".");
saveAs("tif", resultsPath+File.separator+img[0]+"_processed.tif");
Table.save(resultsPath+File.separator+"Results.csv");
exit();
// imagej-macro "saveDemo" (Herbie G., 12. Oct. 2019)

From what you write I see that you use rather imprecise formulations:
"[...] files are [...] saved in the same file as the directory [...]"

This may not harm our conversation but sloppy formulations are a no-no in
programming! That said:
Please be exact when coding and check your code again and again.

Good luck

Herbie

:::::::::::::::::::::::::::::::::::::::::

Creating a directory and saving files in it seems really easy from all the
tutorials and everything, but in practice it seems absolutely impossible.
Whenever I am able to get a directory folder titled "Results", the files are
never saved there, either not saved at all, or saved in the same file as the
directory, just not the directory itself. I'm simply trying to create a
directory titled "Results", and I want to save image and text files in it.
Can someone please help me out with a code that will do this?

Thank you.





--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Please help: Creating a directory and saving files automatically

LyleBabcock
Thank you. It was my use of the File.separator that was messing me up.



--
Sent from: http://imagej.1557.x6.nabble.com/

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