Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 40,912 of 42,547    |
|    Todd Vargo to John Harris    |
|    Re: Batch file to Stripping zeros from p    |
|    28 Feb 14 17:19:00    |
   
   From: tlvargo@sbcglobal.netz   
      
   On 2/28/2014 10:51 AM, John Harris wrote:   
   > What I want to do is run batch file to strip of the leading zeros from the   
   page number at the end of the file name.   
   >   
   > I thought of doing this generically but i need the date format left alone.   
   >   
   > So 0101 becomes 101 or 090 become 90, 01 becomes 1.   
   >   
   > The files will be located in directory/folder.   
   >   
   > I started to look at number count to positions, but not sure if that the   
   best way to do it am a little stuck at the moment suggestion very welcome.   
   >   
   > File name = 05-10-2012#MilitaryPkk-#Books_0101.Pdf   
   >   
   > As you see the its going to be 4, 3 or 2 digits it will in the file name.   
   >   
   > set FRONTEND=%FILENAME:~0,23%   
   > set MIDDLE=%FILENAME:~23,6%   
   > set UNDERSCORE=%FILENAME:~29,1%   
   >   
   > set LOGFILE=c:\testLog.txt   
   > echo FRONTEND: %FRONTEND% >> %LOGFILE%   
   > echo MIDDLE: %MIDDLE% >> %LOGFILE%   
   > echo UNDERSCORE: %UNDERSCORE% >> %LOGFILE%   
      
   If all files have a single underscore a single leading zero in the page   
   number and a single dot ".", then the following may work for you.   
      
   set "filename=05-10-2012#MilitaryPkk-#Books_0101.Pdf"   
      
   for /f "tokens=1,2,3 delims=_." %%a in ("%filename%") do (   
    set "FRONTEND=%%a"   
    set "PAGE=%%b"   
    set "EXT=%%c"   
   )   
      
   echo "%filename%" becomes "%FRONTEND%_%PAGE:~1%.%EXT%"   
      
      
   --   
   Todd Vargo   
   (Post questions to group only. Remove "z" to email personal messages)   
      
   --- 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