Delete old WhatsApp pictures?

Post your questions and help other users.

Moderator: Martin

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Delete old WhatsApp pictures?

Post by MURTUMA » 14 Jan 2015 12:34

I'm trying to make a flow to delete old WhatsApp pictures because I belong to a few groups, which sends them I little too much for my available memory. My goal is to check the specified folder and delete pictures older than five days.

This should be simple, but I don't quite get the grasp of it. The image names are formatted easily to achieve this: IMG-yyyyMMdd-Wxxxxx, where xxxxx is image number.

I should be able to isolate the date from the filename, format it so that Automagic understands it and the calculate, if five days has passed.

I can do the calculations and I have a slight idea of how to isolate the date but I'm totally lost in formatting it right.

Any help is appreciated.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Delete old WhatsApp pictures?

Post by MURTUMA » 14 Jan 2015 12:48

At the moment the init file list action produces following list, which is my starting point:

[/mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140919-WA0000.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140919-WA0001.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140920-WA0000.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140923-WA0000.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140923-WA0001.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140924-WA0000.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20140924-WA0001.jpg, /mnt/sdcard/WhatsApp/Media/WhatsApp Images/Sent]

andy
Posts: 40
Joined: 29 Dec 2014 21:00

Re: Delete old WhatsApp pictures?

Post by andy » 14 Jan 2015 16:48

Hi,

first I would calculate destination day like

delDay=addDays(triggertime, -5); //current date minus 5
searchString=("{delDay, dateformat,yyyyMMdd}") ; //string to be search in file names

Using a for loop you can search inside your path list. Each path that contains search string has to be used for file delete

Regards

andy
Posts: 40
Joined: 29 Dec 2014 21:00

Re: Delete old WhatsApp pictures?

Post by andy » 14 Jan 2015 16:53

For sure, you have to compare islated dates from file names with search string (maybe converted to num) and delete everthing equal or older 5 days

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Delete old WhatsApp pictures?

Post by MURTUMA » 15 Jan 2015 10:18

I'm totally lost here. I couldn't get even the regexp to work. I didn't look at the list operations yet, because I have no idea, where should I even start the script.

Example of one regexp I tried to isolate the date with. I believe that the basics are right and with small modifications it should work. I tried a lot of different things, but no avail.

http://automagic4android.com/flow.php?i ... c2ab3f241f

andy
Posts: 40
Joined: 29 Dec 2014 21:00

Re: Delete old WhatsApp pictures?

Post by andy » 15 Jan 2015 15:38

http://automagic4android.com/flow.php?i ... 943417c1f7

Hi,
here you can find a flow with single script. I generate a list which could be from action init filelist and log messages that describe delete process. You can see how I extract date from filename. Match instruction is not needed in thst case.

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Delete old WhatsApp pictures?

Post by MURTUMA » 15 Jan 2015 16:16

Thanks for thereply but are you sure, you posted right flow?

andy
Posts: 40
Joined: 29 Dec 2014 21:00

Re: Delete old WhatsApp pictures?

Post by andy » 15 Jan 2015 16:28

//current time minus 5 days
newdate=addDays(triggertime, -5);
deldate="{newdate, dateformat, yyyyMMdd }" ;
log({deldate}) ;
//filename list which could be returned from action init filelist
filelist=newList( "IMG-20150114-W00000", "IMG-20150101-W00000" ) ;
//treat each element of filelist
for (a in filelist)
{
//extract date stamp
filedate={substring(a,4,12)};
log({filedate}) ;
//check if equal or older
if (filedate<=deldate)
{
log("{a} deleted") ;
}
else
{
log("{a} not deleted") ;
}
//
} ;

andy
Posts: 40
Joined: 29 Dec 2014 21:00

Re: Delete old WhatsApp pictures?

Post by andy » 15 Jan 2015 16:29

Ähm.....yes.the link is correct. Its pointed to related flow named FlowScript

I posted script in last post

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: Delete old WhatsApp pictures?

Post by MURTUMA » 15 Jan 2015 20:40

andy wrote:the link is correct.
Because you didn't change the name for the action, AM showed me the original instead of your updated scrip. I had to rename the original script first. Seems like here's a place for a bug report.

How does the substring work? "a" is the variable's name for the file, 4 is where substring starts and 12 where it ends, correct?

Then should I check with expression if the "deldate"is more than 5 days and if true, delete "a" file?

Post Reply