Re: rename folder name
Posted by rtas on Oct 11, 2016; 3:56pm
URL: http://imagej.273.s1.nabble.com/rename-folder-name-tp5017317p5017349.html
Hi,
Thank you for prompt response! I have been tried to understand the code that you kindly made.
However, although I chose the subsubfolder as section##, for example section 2, the code returned the new file name "s34_sec" and no number after the "sec". so i tried and error to change the "subsubNum" in the code. I used lengthOf (subsubDir)-2 instead of lengthOf (subsubDir)-1.
Although this works (see below), I am not quite sure what lengthOf (subsubDir)-2 is getting. Does this mean returning the last two index of name of subsubDir folder? Then should not it return the "(space)2" instead of 2?
I also modified the last part of code, adding the cropping and renaming the jpeg file.
Here is the revised code :
subsubDirPath = getDirectory( "Select subsub-directory" );
a = split( subsubDirPath, "/" );
subsubDir = a[a.length-1];
subDirPath = File.getParent( subsubDirPath );
a = split( subDirPath, "/" );
subDir = a[a.length-1];
print (subDir + "is a subDir" );
print (subsubDir + "is a subsubDir");
subsubNum = substring( subsubDir,lengthOf(subsubDir)-2);//this changed to 2 instead of "1"
subNum = substring( subDir, lengthOf(subDir)-2);
folderName = "s"+ subNum + "_sec" + subsubNum;
File.makeDirectory( subsubDirPath + folderName );
print(folderName + "is a folderName");
output = getDirectory ("select save folder");
print (output);
n = 1;
list = getFileList(subsubDir);
for (i=0; i<list.length; i++) {
if (endsWith(toLowerCase(list[i]),".jpg")){
open(subsubDir + list[i]);
print (list[i]);
makeRectangle(780, 0, 3690, 3456);
run("Crop");
fileName = substring (folderName, 0, lengthOf(folderName)-1); ///fileName (removing "/"as a filename from foldername)
print (fileName, "is a file name");
saveAs("jpg", output+fileName+"_"+n+".jpg"); //manual selection of saving folder and somehow the image is 90 degree turned
close();
n++; }
}
Thank you in advance,
rui