0

Thanks to this post: Remove Last Characters from my filenames in windows

I have been able to partially achieve my goal of removing the last two digits of the filenames in a directory, but I need to apply it to only .log files as other files live in that folder.

I have tried adding the .log part in a number of places, but it hasn't worked.

This script works in as much as it removes the last two characters from the filename correctly, but I need it to only perform it on .log extensions

Any help would be appreciated.

@echo off
setlocal enabledelayedexpansion
set FOLDER_PATH=C:\inetput\wwwroot\logs\
for %%f in (%FOLDER_PATH%*) do if %%f neq %~nx0 (
    set "filename=%%~nf"
    ren "%%f" "!filename:~0,-2!00%%~xf"
)
PAUSE
omega1
  • 1,031
  • 4
  • 21
  • 41
  • 1
    `for %f in (c:\windows\*.log) do echo %f`. See http://stackoverflow.com/questions/41030190/command-to-run-a-bat-file/41049135#41049135 – Noodles Apr 24 '19 at 01:19
  • 2
    Simple, just add `.log` after your asterisk.. `for %%f in (%FOLDER_PATH%*.log) do` – Gerhard Apr 24 '19 at 05:54
  • Thank you both, I will try that. – omega1 Apr 24 '19 at 08:46
  • As you're using `(C:\inetput\wwwroot\logs\*)`, `%%f` will be returned to include that path, therefore you may wish to use `If /I Not "%%~nxf"=="%~nx0"` instead of `if %%f neq %~nx0`. – Compo Apr 24 '19 at 11:41

0 Answers0