View Single Post
  #2613  
Old 22.04.2023, 14:08
aiimaim aiimaim is offline
DSL Light User
 
Join Date: Oct 2017
Posts: 31
Default

Thank you for your input @notice.

So far I've come up with this reduced version of the script:


Code:
var archiveFilePaths = archive.getExtractedFilePaths();

// Iterate through all extracted files in the archive
for (var i = 0; i < archiveFilePaths.length; i++) {
  var archiveFilePath = archiveFilePaths[i];
  var file = getPath(archiveFilePath); // Get a FilePath object
  if (file.getExtension()=="avi" || file.getExtension()=="mpeg" || file.getExtension()=="mpg" || file.getExtension()=="mp4" || file.getExtension()=="mkv") {
    if (file.isDirectory()) { // If it's a directory, traverse its contents recursively
      traverseDirectory(file, function(subFile) {
  	  subFile.renameName("test1 "+subFile.getName().toLowerCase()); // Rename the file to lowercase
      });
    } else { // If it's a file, simply rename it to lowercase
  	file.renameName("test2 "+file.getName().toLowerCase());
    }
  }
}

// Helper function to recursively traverse a directory tree and apply a function to each file
function traverseDirectory(directory, fn) {
  var files = directory.listFiles();
  for (var i = 0; i < files.length; i++) {
    var file = files[i];
    if (file.isDirectory()) {
      traverseDirectory(file, fn);
    } else {
      fn(file);
    }
  }
}
This seems to be working. However when I remove the test-part from the renaming line like this
Code:
file.renameName(file.getName().toLowerCase());
it doesn't work anymore and I have no idea why. (There's no error, yet the file isn't being renamed to lowercase.)

Could this be a windows-related error, since Windows doesn't differentiate between lowercse and upprcase filenames? (Right now I'm testing under windows. The goal is to move it to my nas' headless installation, when it works.)

EDIT: Suspicion confirmed, it works under linux.

Last edited by aiimaim; 22.04.2023 at 17:15.
Reply With Quote