How to specify the path to the directory in.bat file?

I have.bat file, next to the folder (Result).
In the folder are .jpg files with different names.
I'm trying to write .bat file so that it renames all these files in this folder.
It works, but not completely. That's the problem:
It only works in the directory where the files are located.
(I need it .bat file and a folder with files next to it. That would work like this).

setlocal enabledelayedexpansion
set "count=1000"
set a="Result\*.jpg"
for /f "usebackq delims=*" %%f in (`dir /b /o:-d /tc %a%`) do (ren "%%f" file-!count:~1!.jpg
set /a count+=1
)
pause
Author: Артем, 2020-11-07

1 answers

Here's the solution.. You can simply go to the folder by writing the path cd /d Result

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

SetLocal EnableDelayedExpansion Expanding variables via signs (!)
cd /d Result go to the Result folder
set "count=1000" variable in which I denoted the number of zeros file-001.jpg
set a="*. jpg " the variable indicates which files we are looking for.

(dir /b /o:-d /tc %a%)
dir - Displays a list of files and subdirectories. Then we sort it.
/b - Output only file names.
/o:-d - Sort the list of displayed files in reverse order (from new to old).
/tc - Sort by file creation time.
%a% - Calling the variable.

Usebackq Specifies whether to use quotation marks for file names Such as these> ".
Sets the execution of a string enclosed in backquotes as the commandSuch as here> `,
and strings in single quotes are like commands in the character stringSuch as these> '.

Delims=xxx Specifies a set of delimiters. Replaces the default set of delimiters consisting of a space and a tab character.

Perhaps there are other solutions, such as:

pushd "D:\каталог01\каталог02"
dir
pause
:: Команда "popd" в случае необходимости вернёт в качестве текущей директорию,
:: которая была таковой до применения команды "pushd" (используется только с ней в паре).
popd
 0
Author: Артем, 2020-11-08 03:24:37