Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 2078  / 3 Years ago, wed, september 1, 2021, 1:38:25

I am having an issue transferring folders to my external hard drive- I dont want to change formatting on the HD.


So there are 100's of files in the folder, and the error preventing me from copying them is coming from special characters (I dont know exactly which, but I believe its "|" and "." and Im sure there are others. I've been manually renaming/removing these, but it's a pain.


Open to suggestions, but I "guess" im looking for a way to either remove those specific characters from the file name, (would doing that cause an issue with .m4a etc?) , or replace them with an underscore if necessary. The one lead I have is perl rename, but I didnt try this yet.


rename 'y/|/_/' *
like this?


thanks for any suggestions


More From » rename

 Answers
4

Yes the (Perl-based) rename command is a good candidate for this. You can add the -n or --nono option to trial-run the replacements ex.:


   -n, --nono
No action: print names of files to be renamed, but don't rename.

so for example


$ rename -n 'y/|./__/' *|*
rename(foo|bar.baz, foo_bar_baz)
rename(foo|bar|baz, foo_bar_baz)

Note that rename will not let you destructively overwrite files if their names are not unique:


$ rename -v 'y/|./__/' *|*
foo|bar.baz renamed as foo_bar_baz
foo|bar|baz not renamed: foo_bar_baz already exists

Note that . is not a special character in the context of filenames so I'd suggest not actually replacing that.


[#1629] Friday, September 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
homerurhyth

Total Points: 338
Total Questions: 113
Total Answers: 105

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;