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

<< < (2/8) > >>

yarond:
I checked the new version.

Regarding 4, that's not it. Even without the -r flag, the ".\" is still considered a part of the file name.

Example: Trying to clean file names (replace various separators, including decimal dots, with spaces) with a few files in the local directory:

--- ---c:\tmp\test>remv -Evv "[-+._]" " "
 Processing '.\bla.txt'.
 Renaming     '.\bla.txt' to ' \bla.txt' ... error: operation not permitted
 Processing '.\file.with.dots.txt'.
 Renaming     '.\file.with.dots.txt' to ' \file with dots.txt' ... error: operation not permitted
 [STATS] Renamed 0 files (2 failed, 0 skipped).
expected: "bla.txt" left as-is since it doesn't match, "file.with.dots.txt" changed to "file with dots.txt" . But the ".\" at the start doesn't let this happen.

Example: adding a prefix to any file (behavior is the same if the "(.*)" is replaced with something to filter, it just of course happens with the relevant/matching files  ) :

--- ---C:\tmp\test>remv -Evv (.*) "prefix-$1"
 Processing '.\bla.txt'.
 Renaming     '.\bla.txt' to 'prefix-.\bla.txt' ... error: operation not permitted
 Processing '.\file.with.dots.txt'.
 Renaming     '.\file.with.dots.txt' to 'prefix-.\file.with.dots.txt' ... error: operation not permitted
 [STATS] Renamed 0 files (2 failed, 0 skipped).
expected: file "bla.txt" will be renamed to "prefix-bla.txt", same with the other.



There's also another issue here (which would have interfered with the above even without modifying the ".\" ). It seems that it fails to rename anything when -E is used. It uses it correctly in what it shows as the expected file name, but fails to rename with the same "operation not permitted". This is once with -E and once without, same files, seemingly same wanted destination name:

--- ---C:\tmp\test>remv -Evv (a) $1b
 Processing '.\bla-has-dot.txt'.
 Renaming     '.\bla-has-dot.txt' to '.\blab-habs-dot.txt' ... error: operation not permitted
 Processing '.\file.with.dots.txt'.
 [STATS] Renamed 0 files (1 failed, 1 skipped).

C:\tmp\test>remv -vv (a) $1b
 Processing '.\bla-has-dot.txt'.
 Renaming     '.\bla-has-dot.txt' to '.\blab-habs-dot.txt' ... Successfully renamed .\bla-has-dot.txt to .\blab-habs-dot.txt.
 Processing '.\file.with.dots.txt'.
 [STATS] Renamed 1 files (0 failed, 1 skipped).

Tuxman:
 :huh:

You truly make me sad. I'm on it (but off tomorrow)...
I'll report back.

Tuxman:
Now, now.


--- ---> .\a -Evv "hpp" "npp"
 Processing '.\a.exe'.
 Processing '.\constants.hpp'.
 Processing '.\filestats.hpp'.
 Processing '.\help.hpp'.
 Processing '.\remv.cpp'.
 Processing '.\remv.hpp'.
 [STATS] Renamed 0 files (0 failed, 6 skipped).

--- ---> .\a -vv "hpp" "npp"
 Processing '.\a.exe'.
 Processing '.\constants.hpp'.
 Renaming     '.\constants.hpp' to '.\.\constants.npp' ... Successfully renamed .\constants.hpp to .\.\constants.npp.
 Processing '.\filestats.hpp'.
 Renaming     '.\filestats.hpp' to '.\.\filestats.npp' ... Successfully renamed .\filestats.hpp to .\.\filestats.npp.
 Processing '.\help.hpp'.
 Renaming     '.\help.hpp' to '.\.\help.npp' ... Successfully renamed .\help.hpp to .\.\help.npp.
 Processing '.\remv.cpp'.
 Processing '.\remv.hpp'.
 Renaming     '.\remv.hpp' to '.\.\remv.npp' ... Successfully renamed .\remv.hpp to .\.\remv.npp.
 [STATS] Renamed 4 files (0 failed, 2 skipped).
Granted, the ".\.\" part looks inconvenient, but good enough.  ;D
I'll look into it on Wednesday again. Checking in, updating the RAR and leaving you alone for today/tomorrow. :)

4wd:
remv 1.1.1 from the OP.

Some observations, which might be attributable to my appalling lack of RegEx knowledge.

The test subjects in their original positions and a dry run:
remv: Rename files (and directories) with regular expressions

remv: Rename files (and directories) with regular expressions

* Output is munged:

* single line output
* the whole .\.\ thing as well as '.\dir\.\dir\file'
* The executable has renamed itself, it would be better if it excluded itself from the operation, (no matter what name the executable has been given).
* More importantly, the file renaming failed and this, (as indicated by the output), is because the directories were renamed first thus any files within those directories were now non-existent.  I would suggest the renaming start at the lowest level and work up.
remv: Rename files (and directories) with regular expressions

* Same results as above but the output is now multi-line.
* It would be better, (I think), if instead of saying Processing 'something' against items that don't match, it said Skipped 'something'.  It would help with quickly scanning the output to see what was skipped or having the output redirected to a file and searching that for Skipped.

Tuxman:
Why do I even publish software one year in advance if people don't test it before it's too late?  ;D

Not renaming the .exe would require to write one function per platform, as C++ does not have a cross-platform way to find the "current .exe path" as far as I know.  :huh:
Coming closer with version 1.2.0... (attaching above.)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version