Page 1 of 1

Remove zero if file name start with zero batch

Posted: 31 Oct 2014 04:44
by cumhur_28
Hello Everbody
Thanx for your previous helps. I have another question.
I have file names and like months 052014,102014 i need if the first character is zero, remove this character.
İnput:052014
Output52014
like that.
is taht any way to do it.

Thanx for your helps


Cumhur

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 05:04
by Yury

Code: Select all

@for /f "delims=" %%i in ('dir /a-d/b') do @for /f "tokens=* delims=0" %%j in ("%%i") do @ren "%%i" "%%j"

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 05:28
by Squashman
Yury, I believe they only want to remove the leading Zero. Not all zeros.

EDIT: Hmm, I guess that does work. Was thinking you needed to use TOKENS=1* but forgot about how it treats leading delimiters.

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 05:35
by foxidrive

Code: Select all

@echo off
type "file.txt" | repl "^0" "" >"newfile.txt"


This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 05:50
by Yury
Squashman wrote:Yury, I believe they only want to remove the leading Zero. Not all zeros.


Squashman, this construction is designed to remove only the leading zero (zeros). Try it!

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 08:15
by cumhur_28
firstly thanx for your helps and sorry for my english i actually means, remove directories first character

thanx for your helps again


Image

to 52014

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 08:19
by foxidrive
Test this on a directory of test folders - if any of them start with two or more 0 then let me know.

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /d %%a in (0*) do (
   set "folder=%%~nxa"
   ren "%%a" "!folder:~1!"
)

Re: Remove zero if file name start with zero batch

Posted: 31 Oct 2014 08:26
by cumhur_28
foxidrive wrote:Test this on a directory of test folders - if any of them start with two or more 0 then let me know.

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /d %%a in (0*) do (
   set "folder=%%~nxa"
   ren "%%a" "!folder:~1!"
)



thank you so much it works. :)