Remove zero if file name start with zero batch
Moderator: DosItHelp
Remove zero if file name start with zero batch
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
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
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
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.
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
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
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
firstly thanx for your helps and sorry for my english i actually means, remove directories first character
thanx for your helps again

to 52014
thanx for your helps again

to 52014
Last edited by cumhur_28 on 31 Oct 2014 08:19, edited 1 time in total.
Re: Remove zero if file name start with zero batch
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
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.
