file rename + syntax
-
@pattonb said in file rename + syntax:
@DustinB3403 thanks, but this is on a linux server.
doh.
Well crap. here I thought I had that solution.
-
@pattonb if need be I could transfer the files, ( about 50gb), but would rather not.
-
@pattonb it is a solution, and I appreciate the input, and I just may, if the frustration gets too high.
thank you -
@pattonb said in file rename + syntax:
@pattonb if need be I could transfer the files, ( about 50gb), but would rather not.
Have you looked at this?
-
@DustinB3403 I looked at similar. I had to do this a few years back and saved the command lines, then I started 'boning' up again, (today), I thought I had it. but obviously, I did something wrong. I was taking the easy route ( so I thought). The brain isn't working as well as I want today. LOL
-
@pattonb said in file rename + syntax:
@DustinB3403 I looked at similar. I had to do this a few years back and saved the command lines, then I started 'boning' up again, (today), I thought I had it. but obviously, I did something wrong. I was taking the easy route ( so I thought). The brain isn't working as well as I want today. LOL
It is daylight savings, so no harm. My brain is shot too.
-
@DustinB3403 I just may transfer to a windows box, and use your script, just for the powershell experience.
I will let you know. thanks again -
-
@Grey interesting, Has anybody tried it ? It seems to me that powershell syntax is much longer than linux,
my powershell knowledge is quite limited, but may not stay that way........thank you
-
@pattonb said in file rename + syntax:
@Grey interesting, Has anybody tried it ? It seems to me that powershell syntax is much longer than linux,
my powershell knowledge is quite limited, but may not stay that way........thank you
I used it. In fact, I had a similar situation to yours on a linux box and I knew the answer in pwsh terms, but not sh. So, I installed, performed my action and got on with life.
You might ask the @climagic guy on twitter for a linux solution or check out climagic.org for the archives.
-
@Grey where does the destination path go from the above script by DustinB3403
-
@pattonb said in file rename + syntax:
@Grey where does the destination path go from the above script by DustinB3403
There is none. He's using rename-item. It's a direct rename.
Get-ChildItem -Path "G:\Some-Folder" -Recurse
This part searches a folder a subdirectories to create all the file objects for enumeration.
| Rename-Item -NewName {$_.Name -replace '•','' -replace '®','' -replace '™','' -replace '','' -replace '','' -replace '~','' -replace '$','' -replace '','' -replace '','' -replace '','' -replace '/','' -replace '|','-'}
Pipe the list of files to the rename cmdlet that has the -newname function, which acts on the list of -replacements.
The rest handles errors. The parens encaps it to work as a single command line, with error handling.
-
@DustinB3403 I went to a windows box, had some errors, sorted all of them except this one. I put in the command I used.
any assistance is greatly appreciated.the error message first
At line:1 char:154- ... '-'} -ErrorAction SilentlyContinue -ErrorVariable daError) if ($daErr ...
-
~~
Unexpected token 'if' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedTokenand the command I used is,
(Get-ChildItem -Path "D:\bradford_temp" -Recurse | Rename-Item -NewName {$_.Name -replace '~','-'} -ErrorAction SilentlyContinue -ErrorVariable daError) if ($daError.Exception.Message -match " Source and destination path must be different.") { Write-Output "ERROR - There was an error. Pay Attention : [$daError]" }
-
@pattonb said in file rename + syntax:
@DustinB3403 thanks, but this is on a linux server.
Is this a Fedora derivative? If so you need
prename
not justrename
.This should work:
find . -name "*~" -exec prename -n 's/~$//' {} \;
-
works exactly as intended, my sincere appreciation.. Now I have to try and understand, the syntax
and what I missed. All I had to do was change prename to rename ( Debian distro)
thanks, kindly