Community discussions

Topic Author
Posts: 29
Joined: Wed Mar 10, 2010 9:00 am

[API] Remove many files

Wed Nov 16, 2016 8:15 am


I have some script who upload stats to webservice. And sometimes script generate trash file (when webservice is unavailable?). Now I have ~35000 files with 0 length on device.
When I try get list of files (by API, Winbox, Terminal) - device has 100% CPU. Memory not enough for all file listening and device goes to reboot :)

I want to try remove files from API. Maybe I can run '/files/print' with paging.. max count... or something else...

User avatar
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [API] Remove many files

Wed Nov 16, 2016 2:50 pm

Maybe from scripting with
/file remove [find where size=0]
The only loop there is internally from "find", which will eventually give out a list of only the IDs of those files, allowing "remove" to remove them in one fell swoop.

Even if it takes a while to complete, by the end you won't have a single empty file left.

A similar thing can be done from the API too, but it would be less efficient, since the list of IDs would need to be sent back and forth between client and router.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)

Who is online

Users browsing this forum: No registered users and 3 guests