JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 11.02.2025, 16:30
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default Delete empty folders on exit

A script that removed all of the (really) empty folders (without a single file, even a 0 byte file) in the default download folder each time when closing / restarting JD would be good.

After some time there are pretty many folders in the default download folder, so it would be good / clearer removing them.

https://board.jdownloader.org/showth...191#post544191
__________________
Aktuelles Windows
Reply With Quote
  #2  
Old 11.02.2025, 19:12
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,680
Default

Code:
/*
    delete empty folders
    trigger : jdownloader started
*/

var downloadFolder = callAPI(
    "config", "get",
    "org.jdownloader.settings.GeneralSettings", null,
    "DefaultDownloadFolder"
)

getPath(downloadFolder).children.forEach(function(item) {
    item.directory && item.delete();
})
Reply With Quote
  #3  
Old 11.02.2025, 22:27
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default

Very fast, thank you very, very much!
__________________
Aktuelles Windows
Reply With Quote
  #4  
Old 12.02.2025, 02:49
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default

Sorry, I cannot get it working, what is wrong here:

Spoiler:






So there is no folder removed.
__________________
Aktuelles Windows

Last edited by pspzockerscene; 12.02.2025 at 11:38. Reason: Added SPOILER tag
Reply With Quote
  #5  
Old 12.02.2025, 08:32
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,680
Default

To test the script, create an empty folder in the JD default download directory, then click 'test run' in the script top panel, and see if that folder you created is removed.
Reply With Quote
  #6  
Old 12.02.2025, 10:41
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default

OK, thank you, nothing is removed.
__________________
Aktuelles Windows
Reply With Quote
  #7  
Old 12.02.2025, 11:00
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 82,053
Default

@Dockel: how do you test it? click the *Test Run" button.
Script will look look into default download folder (from your settings) and only delete empty folders
__________________
JD-Dev & Server-Admin
Reply With Quote
  #8  
Old 12.02.2025, 11:16
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default

Quote:
click the *Test Run" button.
Yes, I did. The button on the screenshot above.
__________________
Aktuelles Windows
Reply With Quote
  #9  
Old 12.02.2025, 11:37
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 74,378
Default

Here is my assumption on what's going on:
You got the setting "subfolder by package name" activated so your path ends with dynamic tag "/<jd:packagename>".
This will result in the script failing as the path is now wrong.
I've created another version of the script with the following changes:
- Remove trailing "<jd:packagename>" from path
- Throw exception if after path correction, path still does not exist (e.g. due to other dynamic tags used in path)

Code:
Code:
/*
    delete empty folders
    trigger : jdownloader started
*/

var downloadFolder = callAPI(
    "config", "get",
    "org.jdownloader.settings.GeneralSettings", null,
    "DefaultDownloadFolder"
);

// Remove dynamic tag "<jd:packagename>" from the end of the path if present
if (downloadFolder.endsWith("<jd:packagename>")) {
    downloadFolder = downloadFolder.substring(0, downloadFolder.length - "<jd:packagename>".length);
}

// Check if the path exists, otherwise throw an exception
if (!getPath(downloadFolder).exists()) {
    throw new Error("Download folder does not exist: " + downloadFolder);
}

// Delete all subdirectories inside the download folder
getPath(downloadFolder).children.forEach(function(item) {
    item.directory && item.delete();
});
I've tested it and it has worked.
__________________
JD Supporter, Plugin Dev. & Community Manager

Erste Schritte & Tutorials || JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
Reply With Quote
  #10  
Old 12.02.2025, 23:12
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default

Thank you very much! I will try at next occasion.

Quote:
You got the setting "subfolder by package name" activated so your path ends with dynamic tag "/<jd:packagename>".
This will result in the script failing as the path is now wrong.
OK, but why does the part of the path from after the download folder name matter at all? Because just each folder shall be removed independently of the name?

Quote:
// Delete all subdirectories inside the download folder
This means all EMPTY sub directories (and sub sub directories, etc.) inside the download folder?

Ja, geht, gerade probiert.
__________________
Aktuelles Windows

Last edited by Dockel; 13.02.2025 at 00:19.
Reply With Quote
  #11  
Old 13.02.2025, 10:45
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 82,053
Default

Quote:
Originally Posted by Dockel View Post
OK, but why does the part of the path from after the download folder name matter at all? Because just each folder shall be removed independently of the name?
It matters because the script starts at that folder
c:\test -> exists and script can list the content and look for empty folders to delete
c:\test\<jd:packagename> -> does not exist on disk, nothing to list, nothing to delete

Quote:
Originally Posted by Dockel View Post
Ja, geht, gerade probiert.
Perfekt!

@Dockel: Du solltest im Default Ordner keine Platzhalter verwenden/haben, sondern dafür den Paketverwalter nutzen
__________________
JD-Dev & Server-Admin
Reply With Quote
  #12  
Old 13.02.2025, 11:35
Dockel Dockel is online now
JD Legend
 
Join Date: Feb 2020
Posts: 732
Default

Okay, ich verstehe.

Quote:
@Dockel: Du solltest im Default Ordner keine Platzhalter verwenden/haben, sondern dafür den Paketverwalter nutzen
Ja, habe ich auch nicht, nur einen ganz normaler Ordner-Pfad.

Vielen Dank!
__________________
Aktuelles Windows
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 18:03.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.