3

First up - I do not have any experience at all with programming in Android or Linux environments. So, very sorry if this question sounds stupid. Here is what I am looking for:

I use a USB drive in my car for music and I transfer files to this drive from my mobile using an OTG cable. There are around 600+ files in it and the music player in the car just randomly plays them. Problem is, since there are so many files, the player seldom plays the newly added ones.

Hence I was wondering if it would be possible to write a script for this - like a batch script or VBSript in Windows. When run, it would copy the latest 20 or so files, based on the date modified, to some folder, say "New". The script would be placed on the drive, preferably, and next time it is run, it would clear the existing folder and copy fresh files again.

Would this be possible?

Model: OnePlus One Android Version: 6.0.1 Cyanogen OS: 13.1.2

  • 2
    Certainly possible – though the question is how to automate that. For hints, see our automation and especially tasker tag wikis. There are apps like IFTTT, Tasker etc which can react on certain events (e.g. a given BT device connects) and then perform defined actions (here you could place your script). Just a raw idea, I didn't yet have that specific use-case :) – Izzy Oct 25 '16 at 9:36
  • Thanks for the tip, will try that. Even then I wouldn't know how to handle the script part. – AntonyP Oct 25 '16 at 10:19
  • The script part would rather be a general Unix&Linux issue :) If all your files are in the same directory initially: rm -f /target/*; cd /source; for music in $(ls -tr |head -n 20); do cp $music /target/; done (quick raw hack: Delete all files in target directory, get the latest files in source (ls -tr: sort by time descending) and copy the "top 20" (head -n 20) files to the target directory; should work in Bash, but I've not tested it, just put together here in the comment box ;) – Izzy Oct 25 '16 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.