auto-change spaces, etc, in file names?
jim lesurf (2082) 1346 posts |
Can someone point me at a program I can use that will let me batch rename directory and file names to replace spaces, commas, etc in the file or directory names? Prefereably replacing with a ‘_’. I’m currently wading though hundreds of such to add them to a collection. Alas the creator of the files routinely uncluded spaces, and even commas. Which can then be a PITA for later processing and access. |
Dave Lawton (309) 87 posts |
Hi Jim, HTH |
jim lesurf (2082) 1346 posts |
Thanks, I’ll have a look. I thought it just was for ‘renumbering’ names! |
GavinWraith (26) 1532 posts |
Jim, it is not clear to me from your query whether you want to edit a textfile containing file and directory names or whether you want actually to rename some files and directories. If the latter then Nick Roberts’ !Rename is relevant. For both possibilities I tend to use scripts written in RiscLua, either dragged into a StrongED window (for editing a textfile) or dragged into a directory and then run (for renaming files and subdirectories). In the latter case I usually make the script construct an Obeyfile with lots of *Rename commands, so that one has a chance of checking that the commands are correct before they are actually executed. The search and replace possibilities of StrongED are usually sufficient for editing names in a textfile. However, the possibilities are so multifarious that any program that attempts anything more general is going to present the user with the problem of learning its syntax (everybody and his dog use different syntaxes). For that reason I favour a multiplicity of specialized programs rather than a few all-singing-all-dancing generalized programs. It is often simplest to write a script from scratch to solve a particular problem, rather than a more general already-written program. Always happy to oblige, of course, once I am given a complete specification :) |
jim lesurf (2082) 1346 posts |
It is file and directory names that I need to alter. Not the content. Contents I can do fine already. I’ve downloaded and tried the rename program from the above URL and it seems quite different to the one I was aware of from the past. Alas, despite having experimented and read the StrongHelp I clearly haven’t understood something. :-/ The problem is that I have a lot of files in directories and subdirectories where the names have various number so spaces, hard spaces, or in some cases, commas. The commas a rare so the main problem is the hard/soft spaces. I want to convert all of these into underscores. The help seems to be telling me to use
seems to be what the help is advising me to use. (Where between the square braces I put a space and a hard space..) But when I try this I generally get “file name too long” or everything after the first space vanishes. Maybe the problem here is that many of the names have multiple spaces in them. |
Jeff Doggett (257) 231 posts |
If you can’t do it with !Rename then I’d try using plain old enumdir to create a file with a list of the filenames, then use my editor of choice to create an obey/exec file to do the job. |
jim lesurf (2082) 1346 posts |
I just tried enumdir and got problems getting it to recognise a starting directory name that contains a space! |
GavinWraith (26) 1532 posts |
Just experimented. It would appear that Enumdir converts spaces in file or directory names to hard spaces. I have not looked at the source code to see what other mangling it performs. |
jim lesurf (2082) 1346 posts |
I continued to experiment and !Renamer now works OK! I’m using settings that didn’t work before, so maybe something else was wrong. But it will now deal with files OK, but not directories. However that’s OK as it deals with most of the required work. Thanks again for pointing !Renamer out to me. :-) |
Chris Johnson (125) 819 posts |
Surely it is the filer that converts any spaces to hardspaces when the file is saved or renamed. The file names do not contain simple spaces (ascii 32). |
GavinWraith (26) 1532 posts |
I am sure you are right about this. Renaming a filename so that it appears to have a space, and then using OS_FSControl to list the filenames, shows that the apparent spaces are hard spaces. |
Vince M Hudd (116) 527 posts |
FTFY! |