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

<< < (6/8) > >>

4wd:
Yes, it does - so you can match subfolders.  :)-Tuxman (January 14, 2019, 01:17 PM)
--- End quote ---

Not sure you got what I meant:

Would rename     'test\one\three\one\fred.pdf' to 'test\dne\three\one\frd.pdf' ...

Given the Regex I used it looks like the groups were:
test\o(ne\three\one\fr)e(d)

ie. The complete path was handled as a string instead of each component of the path, (directories and file), handled individually, (test, one, three, one, fred - each having the Regex performed against them).

If that's the way it's supposed to work then, no offence, it's going to be the strangest rename program I've ever seen and make working out the Regex a bit more complex, (although it would allow renaming dirs/files based on parent and/or sub-dirs).

Need more clarification.

Of course, it could of just been a complete fluke that I happened to create a directory structure and choose a Regex that would bring about this confusion ...

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?
--- End quote ---

I think this is connected with the point above, is the full path handled as a string or are directories and files handled on their individual names?


--- Code: Text ---ls * | sed -E 's/(.*)text(.*)to(.*)remove(.*)/mv & "$1$2$3$4"/' | sh
Would a recursive version be the equivalent of changing to the next sub-dir and performing the same command?

Tuxman:
The full path is handled as a string (and split between path and filename and, optionally, extension during processing). I admit that some features can be confusing even to me.  ;D

So here's how it is intended to work:


* remv "a" "b":
The current directory is processed, all sub-directories are ignored. Folders won't be touched at all.
* remv -r "a" "b":
The current directory and all of its sub-directories are processed. If a path matches, it will be renamed.
- a.txt will be renamed to b.txt
- a\some.txt will be renamed to b\some.txt fixed with 1.3.0
- However, a\ alone won't be renamed to b\ if no files match.
* remv -dr "a" "b":
The current directory and all of its sub-directories are processed. If a path matches, it will be renamed.
- a.txt will be renamed to b.txt
- a\some.txt will be renamed to b\some.txt
- a\ alone will also be renamed to b\ if no files match.
 :-[

Tuxman:
I fixed the -E flag with version 1.2.2. That was a really dumb error.

Tuxman:
I fixed the somewhat anti-logical behavior of the -d flag with version 1.3.0. It should match the README now less badly.

4wd:
EDIT: You uploaded 1.3.0 while I was typing this, so used 1.3.0.

Still trying to work out what's supposed to happen w.r.t. paths/files using Regex so:

remv -sndrvv "o(.+)e(.+)" d$1$2 test

Acting on:
\test\test2\One\two\three\ozorroee\ofile.text

What do you think should be the expected outcome, (before running remv on it - what do you think the final full path should be)?

BTW, it suggested three (3) renames but did four (4)  ;)


And wait until you try non-greedy Regex:

remv -sndrvv "o(?:.+)e(.+)" d$1$2 test

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version