Recently I needed to do something similar. Seems the wildcarding in the Windows command window is pretty lame. I had to generate a batch file with separate lines for each file to be renamed. Codewright didn't have any trouble with doing the name text replacement.
Still, I'd like to get something that is still live, Codewright has been bought and sold so many times it's a lame duck. I think you can still buy it for $350 or so, but there is ZERO support.
When I was trying to do this the other day I found many web pages explaining how REN could not do this. It can substitute letters based on wildcards, but can't wholesale remove sections of the names. Best to use an editor to edit a file list into a set of individual REN commands.
Others seem to have found tools that let them do what they want.
I did not check it but I think you can get "vi" for Windows in some form. Cross-compiled version of vim under cygwin or similar.
However, you will only consider that a "good editor" after you have spent considerable time training your brain and fingers to issue commands like the above without having to look in the manual.
It is of course much quicker than using the mouse. I have been using vi for 30 years, so no issues with that. (although I now see a small typo in the above... never mind)
My experience is that it is usually a lot more work to code a script that does something like this, than to generate a batch file using a text editor that does the same thing.
The examples shown in this thread confirm that.
Besides, when you write a script you need to be very careful when running it the first time, maybe there is a coding error that makes you lose all your files (or all but one).
When using the editor method, you can review the result much more easily before running it.
Of course a script is the way to go when it is a repeatedly occuring task. For single-shot actions I always use the editor method.
(in Linux it is even easier because you do not have to write the script to a file, you can just type 1G!Gsh in vi to execute the contents of the buffer as a script)
You can use regex's and capture groups with back-references (just like with "real" OS's! :> )
But, I suspect (unless you are very comfortable with advanced regex features) you are more likely to "do damage" as you try to fabricate the *correct* expression for this.
[I don't think there is a "dry run" capability in PS so you test your expression with live filesystem contents]
I beg to differ. The example /bin/sh script I wrote can be given a "dry run" trivially:
for name in * do if [ -d ${name} ] then newname=Z${name#99D} echo renaming $name as $newname # mv ${name} ${newname} fi done
I've been building (reasonably complete) file hierarchy instances via a script (i.e., script has to execute as root in order to be able to access the entire hierarchy so errors can be *painful*!) and stub each action as above before unleashing it on the live filesystem.
When you're dealing with hundreds/thousands of files, trying to create all the "copy" commands explicitly is way too tedious. E.g. link /dev/[dt]ty0[0-4] instead of ln -h /dev/dty00 $DEST/dev/dty00 ln -h /dev/dty01 $DEST/dev/dty01 ln -h /dev/dty02 $DEST/dev/dty02 ln -h /dev/dty03 $DEST/dev/dty03 ln -h /dev/dty04 $DEST/dev/dty04 ln -h /dev/tty00 $DEST/dev/tty00 ln -h /dev/tty01 $DEST/dev/tty01 ln -h /dev/tty02 $DEST/dev/tty02 ln -h /dev/tty03 $DEST/dev/tty03 ln -h /dev/tty04 $DEST/dev/tty04 The "link()" version can easily be stubbed to indicate all of the commands that *will* be issued without actually doing anything.
[Imagine making a link of /usr/share/man/* "by hand" ]
I think it is all MUCH too cumbersome for a single-shot action as I described earlier. You need to write a script, to run it in dry mode observing the output, then edit and run it again.
I just do: vi !!ls /dev/[dt]ty0[0-4] :%s!.*!ln -h & DEST/&! (look at what it is going to do)
powershell includes "cmdlets", filtering, globbing and many more bash/sh/csh/zsh concepts. Hence it /not/ just a scripting language.
The OP noted "I've tried variations of the command-line REN command. It renames files, with wild cards, but I can't make it rename directories." and my comment is in that context.
Whether or not you choose to use scripting/globbing/etc is a personal choice which does not affect the ability or otherwise of the cmdlets etc to do what the OP wants.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.