Write last folder naming
Copy link to clipboard
Copied
Hi Friends,
I need your help!
@MY work (write report😞 I need to write last revision folder name only. Also, i was try to some code, that code is write-report for all folder name is given. But. i need to last folder names only. I have place some example screenshot below:
After run my script generate the report. (Wrong Report)
I need report. (correct Report)
My code below:
var Report = new File("C:/Users/karthiks/Desktop/z/Client78_Revision Report.txt" );
Report.open("w");
Report.writeln("Journal Name\tArticle ID\tNumber of Revision\r*********************************\r\r");
var basePath = "C:\\Users\\karthiks\\Desktop\\z"; // Local path:
var basePathFiles = Folder(basePath).getFiles();
var basePathFilesLen = basePathFiles.length;
for (var bsf = 0; bsf < basePathFilesLen; bsf ++){
if (basePathFiles[bsf] instanceof Folder){
var articleFolder = Folder(basePathFiles[bsf].fullName);
var articleFolderSubFolders = articleFolder.getFiles();
var articleFolderSubFoldersLen = articleFolderSubFolders.length;
for (var i=0; i<articleFolderSubFoldersLen; i++){
var currFolder = articleFolderSubFolders;
var currFolderName = currFolder.name;
var articleFolder2 = Folder(currFolder + '\\' + currFolder.name + '_Inputs\\');
var articleFolderSubFolders2 = articleFolder2.getFiles();
var articleFolderSubFoldersLen2 = articleFolderSubFolders2.length;
for (var n=0; n<articleFolderSubFoldersLen2; n++){
var currFolder2 = articleFolderSubFolders2
; var currFolderName2 = currFolder2.name;
//~ alert(currFolderName2);
if (articleFolderSubFoldersLen2 > 4){
//***************************** something i have missing code here *********************
Report.writeln(articleFolder.name + "\t" + currFolder.name+ "\t" + currFolderName2 + "\n")
}
}
}
}
}
Report.close();
please suggest friends.
Thanks in Advance.
KS
Copy link to clipboard
Copied
HI,
This my folder structure:
Thanks in Advance.
KS
Copy link to clipboard
Copied
If you do this:
var currFolder2 = articleFolderSubFolders2[articleFolderSubFolders2.length-1].toString().split('_')[0];
var revision = articleFolderSubFolders2[articleFolderSubFolders2.length-1].toString().split('_')[1]
You will have the folder and revision number.
Is that what you are looking for?
Michel
Copy link to clipboard
Copied
Hi SW,
Thanks to your replay,
Is that what you are looking for? ----> I need to collect for all latest files (project voices) total No.of project above 100.
EXP: Our Folder Structure below:
Project Name --> AHMT --> 108531 --> 108531_Inputs -- > 108531_Final
108531_First Proof
108531_R1
108531_R2
108531_R3
That above structure R2 and before all file default structure this is no needed. But R3 and after received files i need to write report.
*************************
@One more question: I have add your above code in my script. That code alert(Final, First_proof, R1, R2 and R3) for one by one. But i need to alert(R3) latest folder only.
Please suggest friends.
Thanks in Advance
KS
Copy link to clipboard
Copied
Hi,
This structure i like this,
AA | 54321 | R4 |
AHMT | 108531 | R4 |
AHMT | 109587 | R3 |
AHMT | 65820 | R3 |
AHMT | 79060 | R2 |
AMEP | 100660 | R4 |
AMEP | 101099 | R3 |
AMEP | 101395 | R1 |
AMEP | 101698 | R2 |
AMEP | 102000 | R7 |
AMEP | 102081 | R2 |
AMEP | 102111 | R1 |
Thanks
Copy link to clipboard
Copied
Did you place the code outside the for-loop?
I think you do not need the last for-loop.
Michel
Copy link to clipboard
Copied
Hi SW,
Thanks to your replay,
I have used your second code. That code i have modified one number only, after that working good.
Modified code:
var revision = articleFolderSubFolders2[articleFolderSubFoldersLen2-1].toString().split('_')[2] // change 1 to 2.
@One more thing: Some of the project i have received above 14 files "R14". But, Here with alert for only "R9" this code counsel for "R9" is last folder, but 14 folder is there). I have place screenshot for your reference.
Example:
I need to alert for last folder name R14. Please suggest friend
My code also below:
**********************************
var Report = new File("C:/Users/karthiks/Desktop/z/Client78_Revision Report.txt" );
Report.open("w");
Report.writeln("Journal Name\tArticle ID\tNumber of Revision\r*********************************\r\r");
var basePath = "C:\\Users\\karthiks\\Desktop\\z"; // Local path:
var basePathFiles = Folder(basePath).getFiles();
var basePathFilesLen = basePathFiles.length;
for (var bsf = 0; bsf < basePathFilesLen; bsf ++){
if (basePathFiles[bsf] instanceof Folder){
var articleFolder = Folder(basePathFiles[bsf].fullName);
var articleFolderSubFolders = articleFolder.getFiles();
var articleFolderSubFoldersLen = articleFolderSubFolders.length;
for (var i=0; i<articleFolderSubFoldersLen; i++){
var currFolder = articleFolderSubFolders;
var currFolderName = currFolder.name;
var articleFolder2 = Folder(currFolder + '\\' + currFolder.name + '_Inputs\\');
var articleFolderSubFolders2 = articleFolder2.getFiles();
var articleFolderSubFoldersLen2 = articleFolderSubFolders2.length;
if (articleFolderSubFoldersLen2 > 4){
************************************** In below your code ***********************
var revision = articleFolderSubFolders2[articleFolderSubFoldersLen2-1].toString().split('_')[2]
alert(currFolder.name + "/" + revision)
Report.writeln(articleFolder.name + "\t" + currFolder.name+ "\t" + revision + "\n")
}
}
}
}
Report.close();
**************************************
Thanks In advance
Copy link to clipboard
Copied
It has to do with the sortorder of the folders in the parent folder.
You should sort them first like this:
var folders = ['90737_Final','90737_FirstProof','90737_R1','90737_R10','90737_R11','90737_R12','90737_R13','90737_R14','90737_R2','90737_R3','90737_R4','90737_R5','90737_R6','90737_R7','90737_R8','90737_R9'];
var sorted = folders.sort(function(x,y)
{
var f1 = x.split('_')[1].match(/\d+/);
var f2 = y.split('_')[1].match(/\d+/);
return f1-f2;
});
alert(sorted[sorted.length-1].split('_')[1]);
Copy link to clipboard
Copied
Hi SW,
One more thanks,
@Ok right: I understand that (thanks your good explain SW).
@simple one question: How to get folder 14 "R14" alert?
Thanks In advance
KS
Copy link to clipboard
Copied
Well, if you do this:
var sortedFolders = articleFolderSubFolders2.sort(function(x,y)
{
var f1 = x.split('_')[1].match(/\d+/);
var f2 = y.split('_')[1].match(/\d+/);
return f1-f2;
});
alert(sortedFolders[sortedFolders.length-1].split('_')[1]);
You should get the result you want.
Michel

