Rename files with ruby. Once you have a file in a directory you can simply rename it from your code.
The file will be renamed in the same directory. If you want to rename and move it to a new directory, change the variable to_file.
The program below renames an existing file. Make sure the file exists before running the file. You can simply create an empty file.
The file defined by the variable from_file will be renamed to the filename new_file.
Run program with the command:
The file will be renamed to a new file.
Now there are other ways to do this, for example on a Linux or Mac OS X system you can run the command
mv source.txt destination.txt
But this may or may not work on other platforms. Thats why you should always use the modules provides by the programming language.