New recursive batch filename converter
Posted: Thu 17 Feb 2011, 22:59
Renamcon (REcursive NAMe CONverter) is a bash script implementing an Xdialog-based gui for the sed editor. The file renamers that come with Puppy are fine programs, but they do not operate recursively. To manipulate my music and photo files, I needed a program that would deal with thousands of files in hundreds of directories, some of them nested several layers deep. This script does so. It is not designed to replace PRename or gFnRename, but to complement them. It is only a single file, so I did not build a pet for it. Download the attached file, expand it, put it in a directory of your choice (/usr/sbin works well), give yourself permission to execute it, and start by double clicking its name. Alternately, drag it to the desk top, assign it an icon, and start it from there.
Renamcon automates a number of common filename conversions and replacements. It will rename either files or directories, and defaults to recurse through 50 layers of directories, but can be reset to recurse through any number. It processes requests sequentially. First, you select the starting directory and choose whether to accept the default recursion depth or change it -- not much need to change unless you want to limit your search to the current directory (depth = 1) or only a layer or two beneath it, or have directories stacked more than 50 deep. Then you decide whether to process directories, files, or particular files. If you select particular files, you enter the character pattern for the names you want to process (like "*.ogg" to find your music files). Then you jump to the main menu where you can select from a list of possible actions. You can execute multiple actions one after the other, or restart in order to select other files or directories. Read the mini-help file there for additional information.
The linux find command is used to locate the files to be processed. It is very fast. It lists all 59,000 files in my computer (2.53 GHz Celeron running Wary 5.0) in about 3-4 seconds . However, the items in the main menu examine each file matching your search criteria on a line-by-line basis. This is much slower. It takes about 40 seconds for my computer to list changes to 2500 files, and 35 seconds to implement those changes. So if you need to search for a particular pattern to replace, do it when you are asked for particular files, and not from the main menu.
After the potential changes have all been found, they are presented to you for confirmation in an Xdialog editbox. This widget lets you edit its contents, so you can make additional changes there if you want to. I don't recommend it. One of the nice features of doing everything sequentially is that if you make a mistake in any step, it is relatively easy to recover from it. Making arbitrary and random changes can only be corrected manually, if you can locate them again. And do not change the path names in the confirmation box because if you change a path name the program may not be able to find any files pointed to by the old path name.
I also recommend that if you are processing large numbers of files, or having trouble with renamcon, that you run it in a terminal. It will print its intermediate steps to the terminal so you can see what it is doing.
You can also use Renamcon as a simple file finder. Enter the starting directory, and choose particular files. Enter the appropriate search pattern, and from the main menu, select List only. It will locate and display all files matching your pattern.
In addition, Renamcon counts all the files matching your criteria giving you a quick reckoning of how many of what are in your computer.
This is its first release, so let me know if you encounter any problems. Feel free to modify the script for your own use, but if you pass it on, please comment any changes you have made.
Edit: In response to Flash's request, if you select 'Directories' and then 'List only' from the main menu, the directory listing will appear in treeview format with each subdirectory indented by 3 hyphens from the next higher level. Updated file attached.
Renamcon automates a number of common filename conversions and replacements. It will rename either files or directories, and defaults to recurse through 50 layers of directories, but can be reset to recurse through any number. It processes requests sequentially. First, you select the starting directory and choose whether to accept the default recursion depth or change it -- not much need to change unless you want to limit your search to the current directory (depth = 1) or only a layer or two beneath it, or have directories stacked more than 50 deep. Then you decide whether to process directories, files, or particular files. If you select particular files, you enter the character pattern for the names you want to process (like "*.ogg" to find your music files). Then you jump to the main menu where you can select from a list of possible actions. You can execute multiple actions one after the other, or restart in order to select other files or directories. Read the mini-help file there for additional information.
The linux find command is used to locate the files to be processed. It is very fast. It lists all 59,000 files in my computer (2.53 GHz Celeron running Wary 5.0) in about 3-4 seconds . However, the items in the main menu examine each file matching your search criteria on a line-by-line basis. This is much slower. It takes about 40 seconds for my computer to list changes to 2500 files, and 35 seconds to implement those changes. So if you need to search for a particular pattern to replace, do it when you are asked for particular files, and not from the main menu.
After the potential changes have all been found, they are presented to you for confirmation in an Xdialog editbox. This widget lets you edit its contents, so you can make additional changes there if you want to. I don't recommend it. One of the nice features of doing everything sequentially is that if you make a mistake in any step, it is relatively easy to recover from it. Making arbitrary and random changes can only be corrected manually, if you can locate them again. And do not change the path names in the confirmation box because if you change a path name the program may not be able to find any files pointed to by the old path name.
I also recommend that if you are processing large numbers of files, or having trouble with renamcon, that you run it in a terminal. It will print its intermediate steps to the terminal so you can see what it is doing.
You can also use Renamcon as a simple file finder. Enter the starting directory, and choose particular files. Enter the appropriate search pattern, and from the main menu, select List only. It will locate and display all files matching your pattern.
In addition, Renamcon counts all the files matching your criteria giving you a quick reckoning of how many of what are in your computer.
This is its first release, so let me know if you encounter any problems. Feel free to modify the script for your own use, but if you pass it on, please comment any changes you have made.
Edit: In response to Flash's request, if you select 'Directories' and then 'List only' from the main menu, the directory listing will appear in treeview format with each subdirectory indented by 3 hyphens from the next higher level. Updated file attached.