as of right now I have a file called song.mp3 that I have integrated into a Python program which will act as an alarm. I would like it so that whenever I send the Raspberry Pi a new song via Bluetooth, it will just automatically rename this song to be song.mp3, thereby overwriting the previous song. That way I don't have to change my alarm program for different songs. Any help?
Asked
Active
Viewed 216 times
0
-
Or maybe is there a way to constantly check a directory for new files, and then automatically rename those new files? Thanks – Aidan Smith Apr 07 '17 at 00:10
-
There's a technique called _Poll the directory with os.listdir_ in Tim Golden's Python Stuff article [_Watch a Directory for Changes_](http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html) that might be good enough. I've also heard of some Linux-only modules that do this sort of thing, but I don't recall their names. Also see [**_How do I watch a file for changes?_**](http://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes) – martineau Apr 07 '17 at 01:40
1 Answers
0
Assuming that the mp3 files are all in the same directory, you could perhaps have a cron job running that periodically renames the most recent file and so something like:
mv $(ls -1t *.txt | head -1) song.mp3
This is a quick example. It would be more preferable to add the ablve to a script and add some "belts and braces" to ensure that the script doesn't crash.

Raman Sailopal
- 34
- 2