In a single file, write a program that requires no input and produces no output. When run it should reverse the name of the file it is contained in, regardless of what the name is, without altering the code or producing other lasting side effects.
Any way of achieving this is fine. It only matters that once the program is run the only lasting change is that its file name has been reversed. e.g. no new files should be in the directory.
Running the program again should reverse the name back. Indeed, the program should be able to be run arbitrarily many times.
For the purposes of this challenge:
- You may assume filenames are always strings of lowercase letters (a-z) between 1 and 127 characters long. (If your language requires files to have extensions to run then just reverse the part before the extension, e.g.
mycode.bat
→edocym.bat
.) - You may assume the code file is in a directory by itself so it will not have naming conflicts (except with itself).
- You may not assume the filename is not a palindrome, i.e. the same when reversed. Filenames that are palindromes should work just as well as those that aren't.
- You may read your file's contents or metadata. There are no quine restrictions here.
- You may assume your program will be run on a particular, modern, commonplace operating system (e.g. Windows/Linux), since not all shells have the same command set.
As a concrete example, say you have a Python program in a file called
mycode
in its own directory. Runningpython mycode
in the terminal should result in the filename being reversed to
edocym
. The fileedocym
should be alone in its directory - no file namedmycode
should exist anymore. Runningpython edocym
will reverse the name back to
mycode
, at which point the process can be repeated indefinitely.If the same Python file was renamed
racecar
(without changing the code) and then runpython racecar
nothing should visibly change since "racecar" is a palindrome. That same goes if the filename were, say,
a
orxx
.
The shortest code in bytes wins. Tiebreaker is higher voted answer.