Edit: This issue was solved in another issue I posted Here, This is closed.
So I figured this would be an easy one but I can't seem to find anything on how this is done on Google nor on StackOverflow.
So basically what I'm doing is I am using the following code constructed with fs.readdir below...
var workDir = 'C:/Users/user/path/to/MyFolder';
fs.readdir(workDir, function (err, filesPath) {
if (err) throw err;
var result = [];
result = filesPath.map(function (filePath) {
return filePath;
});
console.log(result);
});
...which allows us to read a specified working directory and then print the first set of contents (i.e subdirectories and files) inside of this working directory like so...
[
'EmptyFile.txt',
'Empty.txt',
'emptyDir',
'dirEmpty',
'noContent',
'folder',
'folder_classes2',
'folder_classes3'
]
What I want to do from here, is retrieve the very last instance of all of the folder_classes** subdirs, and then create a new folder_classes** subdir following the number pattern from the title of the previous/last folder_classes** subdir, and unfortunately I don't know how I would achieve this, Google is no help nor did I find anything on Stackoverflow.
It's important to note that these folder_classes** directories follow a number pattern of 2 through 1000.
For those that don't understand, here's an example of what I'm trying to achieve...
Example 1
<MyFolder>
|— folder
|— folder_classes2
|— folder_classes3 // <= function finds this subdir to be last subdirectory
|— folder_classes4 // <= so this new directory
// is created by the function
// following the number pattern
// in the previous `folder_classes**` subdirectory title
Example 2
<MyFolder>
|— folder
|— folder_classes2
|— folder_classes3
|— folder_classes4 // <= function finds this subdir to be last subdirectory
|— folder_classes5 // <= so this new directory
// is created by the function
// following the number pattern
// in the previous "folder_classes**" subdirectory title
I hope everyone understands what I'm trying to achieve, any sort of help on this problem would be highly appreciated.
If the pattern is always fixed(i.e
folderN, N represents as a number), then you can get all directories and then convert each of them and creates an array of numbers. By having this array you can find the maximum number and predicts the next candidate number.This function can give you an idea of what goes on: