home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,113 of 68,980   
   George H. Compton IV to Tapio   
   Re: Why this batch is not work?   
   02 Jan 18 11:51:47   
   
   From: george_compton@hotmail.com   
      
   On Monday, January 1, 2018 at 1:34:31 PM UTC-8, Tapio wrote:   
   > I found this batch somewhere on internet, when I try to find batch, what can   
   > replace spaces with underscores. Batch not work and I can't figure, why is   
   > not work. Can someone fix thist batch?;   
   >   
   > @echo off   
   >   
   > REM Instructions   
   > REM This script repaces spaces from file names with underscores.   
   > REM If you want to just remove the spaces uncomment lines 30 and 52 and   
   > comment out the lines 29 and 51.   
   > REM set the following parameters.   
   > REM pb is the folder containing the files we want to rename (fullpath)   
   > REM tm is a temporary folder that will be created and deleted. Just put a   
   > folder that does not exist and is not used by anything else (fullpath).   
   > REM all is the file type you want to raname. E.g. *.* for every file, *.txt   
   > for TXTs, *.pdf for PDFs etc   
   > REM you don't have to change anything else   
   >   
   > set pb=   
   > set tm=   
   > set all=*.*   
   >   
   > set pa=%pb%%all%   
   >   
   > setlocal EnableDelayedExpansion   
   >   
   > cd /d %pa%   
   >   
   > set /a count=1   
   >   
   > if not exist %tm% mkdir %tm%   
   >   
   > for /f %%F in (%pa%) do (   
   >   
   >     set name=%%~nF   
   >     set name2=!name: =_!   
   >     REM set name2=!name: =!   
   >     set name3=!name2!%%~xF   
   >   
   >     if !name2! == %%~nF (   
   >         move /y %%~dpF\!name3! %tm%\ >nul   
   >     ) else (   
   >             if not exist %%~dpF\!name3! (   
   >                 if not exist %tm%\!name3! (   
   >                     ren "%%F" "!name3!"   
   >                     move /y %%~dpF\!name3! %tm%\ >nul   
   >                 )   
   >         )   
   >     )   
   >   
   > )   
   >   
   > :rename   
   >   
   > for /f %%F in (%pa%) do (   
   >   
   >     set name=%%~nF   
   >     set name2=!name: =_!   
   >     REM set name2=!name: =!   
   >     set name4=!name2!%count%   
   >     set name3=!name4!%%~xF   
   >   
   >     if !name2! == %%~nF (   
   >         move /y %%~dpF\!name3! %tm%\ >nul   
   >     ) else (   
   >             if not exist %%~dpF\!name3! (   
   >                 if not exist %tm%\!name3! (   
   >                     ren "%%F" "!name3!"   
   >                     move /y %%~dpF\!name3! %tm%\ >nul   
   >                 )   
   >         )   
   >     )   
   >   
   > )   
   >   
   > set /a count = %count% + 1   
   >   
   > set /a loop = 0   
   >   
   > for %%F in (%pa%) do (set /a loop = 1)   
   >   
   > if %loop% equ 1 goto rename   
   >   
   > move /y %tm%\%all% %pb% >nul   
   >   
   > rmdir /s /q %tm%   
      
   Here is a working copy..   
      
      
   @echo off   
      
   REM Instructions   
   REM This script repaces spaces from file names with underscores.   
   REM If you want to just remove the spaces uncomment lines 30 and 52 and   
   comment out the lines 29 and 51.   
   REM set the following parameters.   
   REM pb is the folder containing the files we want to rename (fullpath)   
   REM tm is a temporary folder that will be created and deleted. Just put a   
   folder that does not exist and is not used by anything else (fullpath).   
   REM all is the file type you want to raname. E.g. *.* for every file, *.txt   
   for TXTs, *.pdf for PDFs etc   
   REM you don't have to change anything else   
      
   set pb=C:\New   
   set tm=C:\New1   
   set all=*.pdf   
      
   set pa=%pb%\%all%   
      
   setlocal EnableDelayedExpansion   
      
      
      
   set /a count=1   
      
   if not exist %tm% mkdir %tm%   
      
   for %%F in (%pa%) do (   
      
       set name=%%~nF   
       set name2=!name: =_!   
       REM set name2=!name: =!   
       set name3=!name2!%%~xF   
      
       if !name2! == %%~nF (   
           move /y %%~dpF\!name3! %tm%\ >nul   
       ) else (   
               if not exist %%~dpF\!name3! (   
                   if not exist %tm%\!name3! (   
                       ren "%%F" "!name3!"   
                       move /y %%~dpF\!name3! %tm%\ >nul   
                   )   
           )   
       )   
      
   )   
      
   :rename   
      
   for /R %%F in (%pa%) do (   
      
       set name=%%~nF   
       set name2=!name: =_!   
       REM set name2=!name: =!   
       set name4=!name2!%count%   
       set name3=!name4!%%~xF   
      
       if !name2! == %%~nF (   
           move /y %%~dpF\!name3! %tm%\ >nul   
       ) else (   
               if not exist %%~dpF\!name3! (   
                   if not exist %tm%\!name3! (   
                       ren "%%F" "!name3!"   
                       move /y %%~dpF\!name3! %tm%\ >nul   
                   )   
           )   
       )   
      
   )   
      
   set /a count = %count% + 1   
      
   set /a loop = 0   
      
   for %%F in (%pa%) do (set /a loop = 1)   
      
   if %loop% equ 1 goto rename   
      
   move /y %tm%\%all% %pb% >nul   
      
   rmdir /s /q %tm%   
      
      
   exit   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca