Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
joejames_786
- Posts: 17
- Joined: 12 Feb 2017 05:11
#1
Post
by joejames_786 » 28 Mar 2018 07:24
Hi
I request someone to help me convert this code of eGerman which renames only log files
Now can this code be altered to rename only folders without renaming its content
Code: Select all
@echo off &setlocal
set "numfile=a.txt"
set /p "n="<"%numfile%"
set /a "n=1%n%"
for /f "delims=" %%i in ('dir /a-d /b "*.log"^|findstr /vix "[0-9][0-9][0-9][0-9][0-9]\.log"') do (
set /a "n+=1"
set "f=%%~i"
setlocal EnableDelayedExpansion
ren "!f!" "!n:~-5!.log"
endlocal
)
>"%numfile%" echo %n:~-5%
please help
Thanx in advance
Last edited by
aGerman on 28 Mar 2018 07:33, edited 1 time in total.
Reason: code formatting
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 28 Mar 2018 07:50
Did you read the help files for the FOR and DIR commands? I am betting not because otherwise you would know what the original code is doing that was already given to you.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#3
Post
by aGerman » 28 Mar 2018 07:51
Untested:
Code: Select all
for /f "delims=" %%i in ('dir /ad /b ^|findstr /vx "[0-9][0-9][0-9][0-9][0-9]"') do (
set /a "n+=1"
set "f=%%~i"
setlocal EnableDelayedExpansion
ren "!f!" "!n:~-5!"
endlocal
)
The rest of the code should work unchanged.
Steffen