M
M
Mikhail Lyalin2018-04-10 16:02:43
cmd/bat
Mikhail Lyalin, 2018-04-10 16:02:43

Rename files in subdirectories by mask via script in Windows?

There are files with different names with different extensions in subdirectories like ABC_2018-0n0n-nnnnnn.* [ABC - file name of arbitrary length, n-different digits]
You need to get ABC.* from them with a recursive traversal of all nested directories.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
benipaz, 2018-04-10
@mr_jok

https://www.den4b.com/products/renamer

R
res2001, 2018-04-10
@res2001

Renaming option - the script simply cuts off the last 17 characters of the file name. All files in the given directory and its subdirectories are renamed.
Initialize the dirfiles variable with the correct value.

@echo off
SetLocal EnableDelayedExpansion
set "dirfiles=c:\temp\"
for /f "tokens=* delims=" %%a in ('dir /s/b/a-d "%dirfiles%" ') do (
  set "fname=%%~na"
  rename "%%~a" "%%~dpa!fname:~,-17!%%~xa"
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question