ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > DC Member Programs and Projects

remv: Rename files (and directories) with regular expressions

<< < (5/8) > >>

Tuxman:
Nice. I haven't really done much with the PowerShell yet.  :Thmbsup:

4wd:
Unfortunately, I kind of got the $regexReplace wrong :-[
Would have failed if $ignoreExt = $false

Need to directly input the Regex replacement string because of the way PowerShell handles references, (specifically using $ with ' or ") - adjusted script.

Probably a way around it but my brain isn't up to it atm.

Fixed, needed to escape the back references with `

yarond:
Hmm, that might be fixed with a simple call to create_directories before renaming, so the target directories will be created even if the original directories didn't match your regex. But that would lead to empty folders when the files from them have been moved.-Tuxman (January 10, 2019, 06:56 PM)
--- End quote ---
The program is already set to rename/move files, not directories by themselves.
So leaving empty directories behind is both the correct, and expected, behavior. Moving everything out of a directory doesn't necessarily mean that the directory should be deleted, empty directories are a valid entity.

If you want to, it's of course possible to add an optional parameter to check if any directory is being emptied during the run (keep track of location for any file that was moved, and after processing everything check if any of the locations are empty), and then delete them. But, again, while that could certainly be nice, I think it's not required, and it's perfectly fine and normal for empty directories to be left behind if the files inside them were moved elsewhere.

4wd:
Hmm, that might be fixed with a simple call to create_directories before renaming, so the target directories will be created even if the original directories didn't match your regex.-Tuxman (January 10, 2019, 06:56 PM)
--- End quote ---

BTW, I don't know if you noticed but it was suggesting directory name changes even though I hadn't specified the -d parameter.

Actually, looking at the results  again, I would say it's matching against the complete path instead of the individual components of that path.

Tuxman:
Yes, it does - so you can match subfolders.  :)

I don't know if you noticed but it was suggesting directory name changes even though I hadn't specified the -d parameter.
-4wd (January 13, 2019, 04:32 PM)
--- End quote ---

If they are a part of the path to a regular file, yes. You cannot rename a whole directory without a file in it though.
I could make the non-d call skip subfolders, but then -d would be the same thing as not using -r, or am I mistaken?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version