P
P
pkring2019-01-17 13:48:41
cmd/bat
pkring, 2019-01-17 13:48:41

How to rename files using bat file?

5c405c4004b89363498618.jpeg
There is a bat file that must go through all the folders (the folder names are always different) that are in the same directory with it, and in each folder there is an index.txt file, which must be renamed to content.txt. How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey〒., 2019-01-17
@pkring

forfiles /S /M index.txt /C "cmd /c rename @file content.txt"

B
Brendan Castaneda, 2020-11-08
@ae_ph

Here's my solution , it's not an answer to the question, but I want to leave it here for similar requests.
This .bat file will rename .Jpg files from the Result folder into these files file-000.jpg, file-001.jpg, file-002.jpg
The Result folder is next to the bat file.
Initially, in the Result folder, the names of .Jpg files can be completely different .. It does not matter.

setlocal enabledelayedexpansion
cd /d Result
set "count=1000"
set a="*.jpg"
for /f "usebackq delims=*" %%f in (`dir /b /o:-d %a%`) do (ren "%%f" file-!count:~1!.jpg
set /a count+=1
)
pause

SetLocal EnableDelayedExpansion Variable expansion through signs ( ! )
cd /d Result go to the folder Result
set "count=1000" variable in which I indicated the number of zeros file-001.jpg
set "count=1000" The count starts from file-000.jpg then file-001.jpg and so on.
set "count=1001" The count starts from file-001.jpg then file-002.jpg and so on.

set a="*.jpg" variable indicates which files we are looking for.
(`dir /b /o:-d /tc %a%`)
dir - Displays a list of files and subdirectories. Next we sort.
/b - Display only filenames.
/o:-d - Sort the list of displayed files in reverse order ( newest to oldest ).
/o:d - Sort the list of displayed files (oldest to newest).
If you need to change the sort order of files.

%a% - Call the variable
usebackq Specifies the possibility of using quotes for file names Such as > " .
Specifies the execution of a string enclosed in back quotes as commands Such as > ` ,
and strings in single quotes as commands in a character string Such as > ' .delims
=xxx Specifies the delimiter set Replaces the default delimiter set of space and tab.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question