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

<< < (4/8) > >>

yarond:
Hmmm... With 1.2.0 , -nvv shows skipped files, -nv doesn't show skipped files, but does add a newline for each one.
C:\tmp\test>remv -nv f(o+)x f$1$1x
 Can't rename .\fox' to '.\foox' - file exists.
 Would rename '.\foox' to '.\foooox' ...




 [STATS] The simulation suggested 1 renames. Note that some of them might fail.

C:\tmp\test>remv -nvv f(o+)x f$1$1x
 Can't rename .\fox' to '.\foox' - file exists.
 Would rename     '.\foox' to '.\foooox' ...
 Skipping         '.\file.with.dots.txt' ...
 Skipping         '.\blab-habs-dot.txt' ...
 Skipping         '.\b' ...
 Skipping         '.\a' ...
 [STATS] The simulation suggested 1 renames. Note that some of them might fail.

--- End quote ---
after deleting the other files:
C:\tmp\test>remv -nvv f(o+)x f$1$1x
 Can't rename .\fox' to '.\foox' - file exists.
 Would rename     '.\foox' to '.\foooox' ...
 [STATS] The simulation suggested 1 renames. Note that some of them might fail.

C:\tmp\test>remv -nv f(o+)x f$1$1x
 Can't rename .\fox' to '.\foox' - file exists.
 Would rename '.\foox' to '.\foooox' ...
 [STATS] The simulation suggested 1 renames. Note that some of them might fail.

--- End quote ---

Tuxman:
"-vv" shows more stats indeed. This is intended. :)
OK, the newline is ugly, granted...

4wd:
remv 1.2.0

OK, something seems to be wrong:

Initial structure:
remv: Rename files (and directories) with regular expressions


--- Code: Text ---K:\>remv -Ervvns o(.+)e(.+)$ d$1$2 test Would rename     'test\two\one\two.pdf' to 'test\twd\on\two.pdf' ... Skipping   'test\two\one'. Skipping   'test\two'. Skipping         'test\three\two\one.pdf' ... Skipping   'test\three\two\one'. Skipping   'test\three\two'. Skipping         'test\three\three.pdf' ... Skipping   'test\three'. Would rename     'test\one\two\harry.pdf' to 'test\dn\two\harry.pdf' ... Skipping   'test\one\two'. Would rename     'test\one\three\one\fred.pdf' to 'test\dne\three\one\frd.pdf' ... Skipping   'test\one\three\one'. Would rename     'test\one\three\evie.pdf' to 'test\dne\three\vie.pdf' ... Skipping   'test\one\three'. Skipping   'test\one'. [STATS] The simulation suggested 4 renames. Note that some of them might fail.
Taken from the top for the 'Would rename ...' lines, I would have thought given o(.+)e(.+)$ and ignoring extensions:
Would rename     'test\two\one\two.pdf' to 'test\twd\on\two.pdf' ...
'test\two\one\two.pdf' -> 'test\two\one\two.pdf'  - Skip it

Would rename     'test\one\two\harry.pdf' to 'test\dn\two\harry.pdf' ...
'test\one\two\harry.pdf' -> 'test\one\two\harry.pdf'  - Skip it

Would rename     'test\one\three\one\fred.pdf' to 'test\dne\three\one\frd.pdf' ...
'test\one\three\one\fred.pdf' -> 'test\one\three\one\fred.pdf' - Skip it

Would rename     'test\one\three\evie.pdf' to 'test\dne\three\vie.pdf' ...
'test\one\three\evie.pdf' -> 'test\one\three\evie.pdf' - Skip it

ie. None of them match the given criteria.

The actual result:

--- Code: Text ---K:\>remv -Ervvs o(.+)e(.+)$ d$1$2 test Renaming     'test\two\one\two.pdf' to 'test\twd\on\two.pdf' ... error: operation not permitted Skipping   'test\two\one'. Skipping   'test\two'. Skipping         'test\three\two\one.pdf' ... Skipping   'test\three\two\one'. Skipping   'test\three\two'. Skipping         'test\three\three.pdf' ... Skipping   'test\three'. Renaming     'test\one\two\harry.pdf' to 'test\dn\two\harry.pdf' ... error: operation not permitted Skipping   'test\one\two'. Renaming     'test\one\three\one\fred.pdf' to 'test\dne\three\one\frd.pdf' ... error: operation not permitted Skipping   'test\one\three\one'. Renaming     'test\one\three\evie.pdf' to 'test\dne\three\vie.pdf' ... error: operation not permitted Skipping   'test\one\three'. Skipping   'test\one'. [STATS] Renamed 0 files (4 failed, 11 skipped).

Tuxman:
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.

I'm currently experimenting a bit:


--- ---> .\a.exe -Erv "remv" "romv"
 Renaming       '.\remv.hpp' to '.\romv.hpp' ...
   error [rn]: operation not permitted
 Renaming       '.\remv.cpp' to '.\romv.cpp' ...
   error [rn]: operation not permitted
 [STATS] Renamed 0 files (2 failed, 4 skipped).

--- ---> .\a.exe -rv "remv" "romv"
 Renaming       '.\remv.hpp' to '.\romv.hpp' ...
 Renaming       '.\remv.cpp' to '.\romv.cpp' ...
 [STATS] Renamed 2 files (0 failed, 4 skipped).
Something about the -E flag is fishy.  :huh:
I'll look into it tomorrow or on Monday (I'm visiting friends over the weekend). Attaching version 1.2.1 with a broken -E flag above for the time being.

4wd:
FWIW, this is a small PowerShell script I put together to check against what I was testing above:


--- Code: PowerShell ---# Folder to act on$folder = 'K:\test-ps'# Regex to match$regexMatch = "o(.+)e(.+)$"# Regex to replace$regexReplace = "d`$1`$2" # Must remember to escape the back references DOH!# Ignore extension$ignoreExt = $true# Grab the directory tree$a = Get-ChildItem $folder -recurse# Sort by folder depth$b = ($a | Select-Object FullName, @{Name="FolderDepth";Expression={$_.DirectoryName.Split('\').Count}} | Sort-Object -Descending FolderDepth,FullName)# Loop through each file/dir name seeing if it matches and output the resultfor ($i = 0; $i -lt $b.Count; $i++) {  # Output the last part of the path we're testing  Write-Host (Split-Path $b[$i].FullName -Leaf) -NoNewline  if ($ignoreExt) {    # Ignoring extension    # Grab the last part of the path (file/folder)    $t1 = (Split-Path $b[$i].FullName -Leaf)    # Grab name without extension and replace matches    $newName = ([io.path]::GetFileNameWithoutExtension($t1) -replace $regexMatch, $regexReplace)    # Output result    Write-Host " -> $($newName)$([io.path]::GetExtension($t1))"  } else {    # Include extension    # Grab the last part of the path (file/folder) and replace matches    $newName = ((Split-Path $b[$i].FullName -Leaf) -replace $regexMatch, $regexReplace)    # Output result    Write-Host " -> $($newName)"  }}

Sample output
--- Code: Text ---PS Z:\test\_Coding Snacks> Z:\test\_Coding Snacks\remv-test.ps1fred.pdf -> fred.pdftwo.pdf -> two.pdfone.pdf -> one.pdfharry.pdf -> harry.pdfevie.pdf -> evie.pdfthree.pdf -> three.pdfone -> onetwo -> twoone -> onetwo -> twothree -> threetwo -> twoone -> onethree -> threeone -> one

No guarantee it's correct either  ;)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version