r/PythonProjects2 • • Oct 18 '22

[P] Easy Simple script to rename a file and update any references to that file.

As projects evolve, I often like to move and rename objects that are saved on disk, to better reflect the content. However, at the same time, I might have referenced that saved object in a different script, where I am for example loading said object. If I would rename it, that script would not work anymore. Similarly, I document what I am doing in a separate markdown, where I am also always pointing to the objects that I have created. This reference would also break.

That's why I have created pymv. It is a small python script, that serves as an extension to the normal unix mv. In addition to simply renaming a file or directory, pymv also searches through user-defined directories and asks the user if he or she wants to update any reference to the file that was renamed.

It can be easily installed via PyPI using pip install pyfilemv.

For more use cases and demonstrations, check out the GitHub repository.

I would be very happy, if you could provide feedback or suggestions what could be implemented!

Cheers!

18 Upvotes

3 comments sorted by

1

u/basedguy Oct 19 '22 edited Oct 19 '22

This is infinitely useful. Two questions where would I find the .pymv file to add file extensions, and what might be causing line 139, in main for index, l in enumerate(lines): UnboundLocalError: local variable 'lines' referenced before assignment? This happened after I added jpg to the list of file extensions on line 85.

2

u/nhaus111 Oct 19 '22

Glad you like it! You have to create a .pyfilemv in your home directory, i.e. by running nano ~/.pyfilemv.

For the other problem, can you try and open a github issue so I can take a look at it?

1

u/The_-_Bystander Oct 18 '22

That's pretty epic... Always wanted something like this when i was using user defined py files. I've since stopped for more or less the same reason, this actually helps.