A
A
Alexey2017-12-13 14:34:42
cmd/bat
Alexey, 2017-12-13 14:34:42

How to make a unique save without using a date in a batch file?

Current code:

set dir1=C:\TEST\ScanTo\
set strTime=_%Date%_%Time%
set strTime=%strTime::=-%
set strTime=%strTime:,=-%
set strTime=%strTime:/=-%
%SYSTEMDRIVE%

I want to save:
scan_1
scan_2
scan_3
...
Let's say I deleted the scan data and the counter should start over, i.e. there should be some kind of check at the beginning of the code.
The strTime variable is essentially a counter with a check for uniqueness

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Kuts, 2017-12-13
@fox_12

Create a file - for example
count.txt
and store an intermediate value for the increment
there. Deleted the scans and you have to start over - delete the file.

O
Olgeir, 2017-12-13
@Olgeir

if the file names differ only by the number and the number is a constant number of digits, i.e. not scan_1, but scan_000001, scan_000002, scan_000003, then you can:
@echo off
for /f %%a in ('dir /b /on "scan_*. jpg"') do set tmp=%%a&goto lev1
:lev1
echo %tmp%
set /a next_file_num=%tmp:~-10.6% +1
set next_file_num_str=000000%next_file_num%
set next_file_num_str=%next_file_num_str:~-6 %
set next_file_name=scan_%next_file_num_str%.jpg
echo %next_file_name%

E
Eugene, 2017-12-13
@yellowmew

Your "variable" value is the number of files in the folder.

@for /F %%a IN ('attrib.exe ./*.* ^|find /c /v ""') DO @set result=%%~a
@echo %result%

use the result variable as you please

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question