@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
rem The following settings for the source directory, destination directory, target directory,
rem batch directory, filenames, output filename and temporary filename [if shown] are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:your files"
SET "destdir=u:your results"
SET "filename1=%sourcedir%q65529783.csv"
SET "outfile=%destdir%outfile.csv"
(
FOR /f "usebackqtokens=1-7delims=," %%a IN ("%filename1%") DO (
FOR /f "tokens=1-4delims=." %%s IN ("%%d.%%e") DO SET /a value=(%%s*100000^)+1%%t-(%%u*100000^)-1%%v&SET /a value=10*value+1
ECHO %%a,%%b,%%c,%%d,%%e,%%f,!value!
)
)>"%outfile%"
GOTO :EOF
I used a file named q65529783.csv
containing your data for my testing.
Produces the file defined as %outfile%
The usebackq
option is only required because I chose to add quotes around the source filename.
First, read and tokenise using ,
- 7 columns, so tokens 1-7, although the last is unused.
Next, re-tokenise the string %%d.%%e
using .
as a delimiter. Note the dot between %%d
and %%e
.
Now set our value. Since there is no indication of the value-ranges involved (I have assumed that they are all positive) then we convert %%d
to a six-digit number by multiplying %%s
by 100000 and adding 1%%t
to that. This takes care of the situation where %%t
contains a leading 0 which would otherwise be treated as octal.
Rinse and repeat for %%e
and perform the subtraction, noting that the 1
preceding %%v
balances that preceding %%t
. The carets are required so that cmd
sees the )
as part of the set
, not the for
.
Since the result is now 10000* the floating-point difference, multiply by 10 and add 1, as anticipated in the original code.
and output the result.
Since you don't explain why the first result of the manipulation is 120
, which seems illogical given the formula, I'll assume that this is an error and it should be 121
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…