VideoHelp Forum




+ Reply to Thread
Results 1 to 5 of 5
  1. Hi,

    please have patience with the cat

    Image
    [Attachment 86417 - Click to enlarge]


    thanks.

    I try to do a renamer for files with special character in powershell

    Code:
    dir | % {$_ | rename-item -NewName $_.name.replace('%','').replace('#','').replace('_',' ').replace('!',' ').replace('[',' ').replace(']',' ').replace('{',' ').replace('}',' ').replace('&',' ').replace('?',' ').replace(',',' ').replace(';',' ').replace(':',' ').replace('$',' ').replace('^',' ').replace('\',' ').replace('"',' ').replace('@',' ').replace('*',' ').replace('(',' ').replace(')',' ').replace('-',' ').replace('=',' ').replace('+',' ').replace('/',' ').replace('.',' ').replace('>',' ') -ErrorAction SilentlyContinue}
    but this acts on ALL file, meanwhile I need it acts only on *.mp3 and *.mp4 files

    How I can do ?
    Quote Quote  
  2. (Coming from there, this thread was listed below “Similar Threads”.)

    A cat with PowerShell is like a chimpanzee with a machine-gun.

    But in case you still haven't found, it should be something like:
    Code:
    ForEach ($file in GCI *.mp3 *.mp4) {
    ...
    (GCI being a shorthand for “Get-ChildItem”.)
    Not sure about how to properly use this with the rest of the script – I'll try to make some tests as it could come in handy.
    It may be possible to simplify the command if several characters are to be replaced by a space, but I wouldn't know how.
    How can there be valid file names with characters like “\” or “/” or “>” or “*” or “:” or “?” or “"” on a Windows system?

    Since you seem to be doing quite a few file manipulations beyond video stuff, you might find this interesting.
    Quote Quote  
  3. Use ReNamer GUI, highly recommend: https://www.den4b.com/products/renamer

    In your case, start it,
    --- Click + Add (rule) and select "Delete", add # character "+ Add Rule"
    --- Click + Add (rule) and select "Delete", add % character and select "+ Add Rule"
    --- Click + Add (rule) and select "RegEx" and for Expression use: [^a-zA-Z0-9] and for Replace: just type empty space bar character, select "+ Add Rule"

    Drop your files on GUI (select it before as "type" in Windows explorer so they bunch up with extensions)
    --- Click Preview

    Only when you are satisfied with new name results, click "Rename"


    or I can drop you a python file you can call from batch script, that you can call from batch script
    Quote Quote  
  4. Use ReNamer GUI, highly recommend
    Haven't tried it yet, it seems convenient and flexible. Bulk Rename Utility allows to use regular expressions, but not to define multiple single character replacements simultaneously (well the version I have is from 2021, it could have been improved since...). It does however allow to pre-filter files in a given folder, by extension or any other pattern; in this case it could filter files with a name fitting the “*.mp*” pattern, but that would also display *.mpg files for instance; with regular expressions enabled, “.+\.mp[34]$” would work reliably to display *.mp3 and *.mp4 files only; but I wouldn't know how to display simultaneously two types of files with a completely different extension, for instance *.avi and *.mp4.

    Still, for a task that has to be performed regularly, a script solution might be preferred.
    I have a tiny bit of knowledge of PowerShell, no experience with Python. I'd be eager to learn, as it seems both fairly easy and powerful, but now wouldn't be the right time to learn anything as involved as a programming language.
    Quote Quote  
  5. There could be a python command line utility made that does this (not gui):
    Code:
    python "rename filenames.py" --directory "E:\Videos\extraordinary_cat_videos"  --confirm_renaming --extensions mp4*mp3 --regextodelete [%#] --regextospace [^a-zA-Z0-9]
    That works for PowerShell. For windows batch there must be some escaping done for regex sometimes, in our case it would be --regextospace [^^a-zA-Z0-9]
    or just running exe utility, not needing python installed, below it is for windows batch, not sure now how to call it with arguments now in PowerShell:
    Code:
    "rename filenames.exe" --directory "E:\Videos\extraordinary_cat_videos"  --confirm_renaming --extensions mp4*mp3 --regextodelete [%#] --regextospace [^^a-zA-Z0-9]
    --- if directory argument is not in command line, executable directory is used (same directory as py or exe file is in)
    --- if flag --confirm_renaming is removed, renaming is not waiting for confirmation, DO ONLY IF EXPERIENCED what this all does
    if starting to be familiar with this, better to leave it there , look at printed files (originals and would be renamed) and then confirm y/n if wanting renaming
    --- extensions need to be specified, separated by a star character: "*"
    --- characters in regextodelete argument are characters to be deleted, it is a regex pattern, so in our example characters "%" and "#"
    --- regextospace, characters in regex that will be replaced by space, in our example "^" makes it opposite, so if not alphabetic characters or digits, they will be replaced by space

    so it is flexible, regex variables could be changed a bit for different needs
    Image Attached Files
    Last edited by _Al_; 17th Mar 2026 at 22:27.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!