Git Product home page Git Product logo

linux_file_rename_utility's Introduction

Linux File Rename Utility

Application

Linux File Rename Utility

Author

BSFEMA (https://github.com/BSFEMA)

Purpose

To provide Linux with a good file rename utility. I didn't particularly like any of the existing rename utilities available on Linux and I didn't like having to run a Windows one in Wine either... This was also a good excuse to learn Gtk and Glade programming with Python.

Installation

There really isn't an "install" for this since it is just a python script and a few other files. With that said, there are a few different ways to 'download' it:

###The 'git clone' method: Clone the repository. In a terminal navigate to where you want the folder to be created and the files downloaded into, then run the following command:

git clone https://github.com/BSFEMA/linux_file_rename_utility.git

Please note that this method will create a hidden ".git" folder. If you just want the program files and nothing else, feel free to delete this folder.

###The 'git download zip' method: On the main linux_file_rename_utility repository page, you can click on the green "Code" button, then click on the "Download Zip" option. You can then extract the contents where you want to store the application.

###The 'curl' method: Download the individual files directly. Create a folder to store the files, navigate to it in a terminal window and run the following commands:

curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.py
curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.glade
curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.css
curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.svg
curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/README.md
curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/CHANGELOG.md
curl -LJO https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/LICENSE

###The 'wget' method: Download the individual files directly. Create a folder to store the files, navigate to it in a terminal window and run the following commands:

wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.py
wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.glade
wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.css
wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/linux_file_rename_utility.svg
wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/README.md
wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/CHANGELOG.md
wget --no-check-certificate --content-disposition https://raw.githubusercontent.com/BSFEMA/linux_file_rename_utility/master/LICENSE

Command Line Parameters

  • If the first parameter is a valid folder path, then that will be used to start renaming files from. If this value isn't provided, then the starting path will be where this application file is located. The intention is that you can call this application from a context menu from a file browser (e.g. Nemo) and it would automatically load up that folder.
  • If the first parameter is a valid file path, it will use the folder that the file resides in instead.
  • If you pass it a list of files (e.g. 'file:///home/user_name/file1.txt', 'file:///home/user_name/file2.txt'), it will use the folder that the first file resides in instead. It will then auto-select all the files that exist in that folder. The intention is that you can use Linux File Rename Utility as the "Bulk Rename" utility in Nemo.
  • If no parameter is passed, then it will use the folder where the "linux_file_rename_utility.py" file is located.

Folders

This application will create a "/.config/BSFEMA/" folder and a "/.local/share/BSFEMA/" folder if they don't exist.

  • The purpose of the "~/.config/BSFEMA/" folder is to store application specific config information (i.e. default, hidden, and saved settings files).
  • The purpose of the "~/.local/share/BSFEMA/" folder is to store application specific data (i.e. history text files for each execution of a rename).

Default settings file

You can add a "settings.txt" file to the "/.config/BSFEMA/" folder (i.e. "/.config/BSFEMA/settings.txt"). If this file exists, it will be used as the default settings to apply each time the application is launched. This file holds all of the application settings that will be initially loaded. You can use the "Save Settings to File" button and overwrite the "settings.txt" file.

Hidden settings file

You can add a "hidden_settings.txt" file to the "/.config/BSFEMA/" folder (i.e. "/.config/BSFEMA/hidden_settings.txt"). If this file exists, it will be used as the default settings to apply each time the application is launched. This file holds a few settings that are not stored in the normal settings.txt file. Here is the complete list of options that you can set in the file:

"hidden_settings.txt" contents:

# The following are various settings that you cannot set through the UI
# Please see the line above each setting for the appropriate values
# Commenting the line out (i.e. adding a '#' to the beginning of the line), the applicaiton will use the standard default options

##### Start the application maximized:
# Default = False  [blank, commented out, or not set]
# Values:  "True" or "False" only
window_maximize=False

##### Direction of the spinner widgets:
# Default = HORIZONTAL
# Values:  "HORIZONTAL" or "VERTICAL" only
# Notes: "HORIZONTAL" decreases the height compared to "VERTICAL", but increases the width
spinner_orientation=HORIZONTAL

##### Starting vertical height of the data grid:
# Default = 400
# Values:  [integer >= 0]
# Notes:  100 give 3 rows, 400 gives 16 rows (depending on your OS theme)
scrollwindow_Data_Grid=400

##### Show icon on rename button:
# Default = False  [blank, commented out, or not set]
# Values:  "True" or "False" only
# Notes:  This will cause the vertical window size to increase if spinner_orientation=HORIZONTAL
button_Rename_image=False

Personally, I like setting spinner_orientation=VERTICAL & button_Rename_image=True, but that doesn't work on smaller monitors, which is why the defaults are set to the above.

Saved settings files

You can save any configuration to a .txt file and then open/load that settings file at a later time. This is useful if you periodically perform the same rename actions. The settings files are stored in the "/.config/BSFEMA/" folder (e.g. "/.config/BSFEMA/some_saved_settings_file.txt") by default.

Save History files

If you have the "Save History" option checked, it will create a file in the "~/.local/share/BSFEMA/" folder each time the "Rename Files" button is clicked. The filename will be in the format of "%Y_%m_%d_%H_%M_%S_%f".txt (e.g. 2020_12_18_15_20_24_186471.txt). The format of the file is (without spaces): ["File"/"Folder"] | [full path + file/folder name] | [new file/folder name] | [rename status]

Examples:

Folder|/home/example_user/Documents/test_1/|test|Renamed!
Folder|/home/example_user/Documents/test_2/|test|New Name path already exists
File|/home/example_user/Documents/pic_example_with_underscores_1.jpg|pic example 1.jpg|Renamed!
File|/home/example_user/Documents/pic_example_with_underscores_2.jpg|pic example 2.jpg|Renamed!

Possible Rename Statuses

Before clicking the Rename Files button:

  • No change...
  • To be changed

After clicking the Rename Files button:

  • Renamed!
  • New Name path already exists
  • FAILED TO RENAME!
  • Current Name's Full Path doesn't exist

Import Rename Pairs

You can import a "/" delimited list of rename pairs. It will apply this after it has gone through boxes 1-8. The rename pairs must be the full file name including any file extension. Each time the "Import Rename Pairs" button is pressed it will immediately wipe out any existing rename pair information. This means that if you import a rename pair, but want to blank it out, simply click the "Import Rename Pairs" button and then cancel the file open dialog. Any invalid rows will be output to the terminal, with the line number for easy reference.

Example rename pairs .txt file:

1.txt/2.txt
1.txt/3.txt
1.txt/4.txt
subfolder_1/Sub Folder 1

Note: If there are multiple resulting file names for a given file name, it will use the last one. In the above example, "1.txt" will be renamed to "4.txt".

Icon File

If you copy the "linux_file_rename_utility.svg" to "~.local/share/icons", then it should be picked up by the system and can be used as any other icon.

Nemo Action context menu

You can create a nemo action file so that you can right click in a folder and launch the Linux File Rename Utility from there.

Example (filename = "linux_file_rename_utility.nemo_action"):

[Nemo Action]
Name=Linux File Rename Utility
Quote=double
Exec=python3 "<YOUR_PATH_TO>/linux_file_rename_utility.py" %F
Selection=any
Extensions=any
Icon-Name=linux_file_rename_utility

Save the "linux_file_rename_utility.nemo_action" file to "~/.local/share/nemo/actions".

Note: The "Icon-Name" line references the "linux_file_rename_utility" name. Please see the "Icon File" section above for more information on this.

Context menus might be possible for other file managers, but that will be up to you to figure out ;)

With the introduction of v1.7 (supporting command line arguments of a list of files), you can actually have another version of the Nemo action that is for auto-selecting files.

Example (filename = "linux_file_rename_utility_selected.nemo_action"):

[Nemo Action]
Name=Linux File Rename Utility (Selected)
Quote=double
Exec=python3 "<YOUR_PATH_TO>/linux_file_rename_utility.py" %U
Selection=any
Extensions=any
Icon-Name=linux_file_rename_utility

Changing the '%F' to '%U' allows for files selected in Nemo to be auto-selected in the data grid at launch.

Nemo 'Bulk Rename' setting

Instead of 'Bulky', you can use the Linux File Rename Utility. This is so that you can select files in Nemo, press [F2] on the keyboard, the Linux File Rename Utility will launch to the folder where those files are located and then auto-select those files in the data grid.

To enable this, launch Nemo, click on Edit in the menu, select Preferences, click on the Behavior tab, find the 'Bulk Rename' section (at the bottom of the menu), set the command line to something like: python3 "<FULL_PATH_TO>/linux_file_rename_utility.py" e.g. (python3 "/home/user_name/bin/linux_file_rename_utility.py")

CSS

Each UI object (e.g. button, label, etc.) has a name and can therefore have its own unique css applied to it.

Examples:

1. If you wanted all text to be 10pt font, you can set the "window {}" line in the css file to a value of "font-size: 10px;"  This will then filter down to all objects contained within it.
    * window {font-size: 10px;}
2. If you wanted to make just the "button_Rename" object have a specific background and foreground color, you can set the "button#button_Rename {}" line to a value of something like "background: #FF0000; color: #0000FF;".
    * button#button_Rename {background: #FF0000; color: #0000FF;}

Known issues

I have noticed that when you re-order the columns in the data grid that Gtk throws warnings like this:

(linux_file_rename_utility.py:628656): Gtk-WARNING **: 18:50:14.570: Negative content width -15 (allocation 1, extents 8x8) while allocating gadget (node button, owner GtkButton)

Unfortunately, I don't know why this error is being thrown or how to fix it. Just ignore it or don't re-order the columns...

Screenshots

I have uploaded a few screenshots from various Linux distros here: https://imgur.com/a/2jxFVG1

Changelog

See the CHANGELOG.md file.

License

MIT. See the License file.

linux_file_rename_utility's People

Contributors

bsfema avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

linux_file_rename_utility's Issues

No File/Folder Rows displayed in main window when broken link is encountered

This is a pretty rockin' renaming utility, got several features I've been looking for for years in a bulk renamer tool!

An issue that I've run into that is a bit of a show stopper is that when it encounters a broken link, even far deep within subfolders of the selected folder, (which apparently are quite frequent in the /home subfolders buried within program config folders) nothing (no files or folder rows) is shown in the main window. The program GUI responds normally (fields can be entered, different fodlers can be selected,etc.) and doesn't display any warning/indicator of what's wrong - thankfully a Stack Trace is outputted to the console when run from terminal:

Traceback (most recent call last):
  File "linux_file_rename_utility.py", line 275, in entry_Folder_Path_changed
    populate_files_Full(self.builder.get_object("entry_Mask").get_text(),
  File "linux_file_rename_utility.py", line 2279, in populate_files_Full
    part6 = human_readable_filesize(os.stat(part0).st_size)
FileNotFoundError: [Errno 2] No such file or directory: '/home/cc/.mozilla/firefox/ggll95mh.default-release/lock'

I've been looking to get into both Python coding as well as contributing to open source projects so I may try my hand at implementing a fix and submitting a pull request for this; as I've not done so before as far as a public github project is concerned any guidance would be welcome, whether regarding technical points and/or community etiquette

Thanks to the developer for this kickass tool!

Very long loading time with no indicator

Small issue in terms of usage, maybe large as for a fix (or maybe not?), but when a directory is selected (from the top-left dropdown within the GUI) with a particularly large amount of files/folders/subfolders, the GUI simply freezes with no indicator that anything is happening.

Once it's known then it's not a showstopper to using the utility to be sure, but may be off-putting to new users, and in general would be a nice touch to have a spinner going or something for assurance that processing is occurring.

For context this has happened for me mostly with CIFS mounted network drives with nearly 1000 folders and over 5000 files within them, so this may be only an issue in such extreme cases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.