Deleting the contents of a folder

Solved
B
Bartłomiej
NO LIMIT Sp z o.o.

Hi,is it possible to delete the entire contents of a folder without deleting the folder itself using file mannager on devices with android 10.0
We are having mobicontrol version  2024.1.2.1046
We want to delete the contents of the folder located in the path /sdcard/pictures

6 months ago
SOTI MobiControl
ANSWERS
ZC
Zafer Cigdem
6 months ago

Hi,

I used following legacy script earlier that delete all contect under the Camera section, you can use something similar by updating the path:

del %sdcard%\DCIM\Camera\*.*
 
for your case it would be as: 
del %sdcard%\Pictures\*.*
 
I hope it helps.
Zafer
Solution
B
Bartłomiej
6 months ago

Yes, that helped. Thank you very much

RS
Rafael Schäfer
6 months ago

Just if you need something in JS (you can ofc remove the dependency of the creation date):

var days = 180;
purgeOldFiles('sdcard/Pictures');
 
mobicontrol.agent.checkIn();
//Cleanup files older than 180 days
function purgeOldFiles(dirPath) {
    var dir = new mobicontrol.io.File(dirPath);
    var today = new Date();
    var oldestDate = new Date(today.setDate(today.getDate() - days));
    dir.listFiles().forEach(file => {
        if (file.lastModified < oldestDate) {
            file.delete();
        }
    });
}
E
ENMod
6 months ago

Hey Bartłomiej K,

Thanks for posting on SOTI pulse. Thank you Zafer and Rafael for providing the right resolution to the query. 

As they mentioned you can use the scripts they provided which works. If you face any more challenges you can raise more queries on SOTI Pulse or Log a case with us. Thank you!! 

Technical Support, SOTI | Call Us | SOTI.net | Discussion Forum | Log a Case Online