Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch move files with special chars  (Read 6370 times)

0 Members and 1 Guest are viewing this topic.

chaosmstr

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Unknown
    batch move files with special chars
    « on: May 09, 2019, 11:51:03 PM »
    So, I found this one previously:
    https://www.computerhope.com/forum/index.php?topic=152980.0

    Code: [Select]
    @echo off
    setlocal enabledelayedexpansion
    for %%A in (*.*) do (
       echo file found  %%A
       for /f "delims=" %%B in ("%%A") do set fname=%%~nB
       for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
       for /f "tokens=1* delims=-" %%D in ("!fname!") do set folname=%%D
       echo folder name !folname!
       pause
       if not exist "!folname!" (
          echo Folder !folname! does not exist, creating
          md "!folname!"
       ) else (
    rem       echo Folder !folname! exists
       )
       echo Moving file %%A to folder !folname!
       move "%%A" "!folname!"
       )
    echo Finished
    pause

    The batch file works great, except for one thing.

    I'm working with MP3 files, and there's a lot of titles with ! in the name...
    The batch commands aren't catching the special char.

    For instance...
         P!nk - So What.mp3
    The directory name created is
         Pnk
    then there's an error that the file doesn't exist.

    Sooo.. how can I tell it to ignore special chars that can occur anywhere in the filename?