N
Nebulon
I seem to be having a problem with a group of batch files.
There are four -- two I've gotten working, and two with a problem.
First two are:
rand_add.bat
for %%x in (c:\a_particular_path\*) do radd1 "%%x" "%%~nx%%~xx"
radd1.bat
set /a a=%random% %% 10
set /a b=%random% %% 10
set /a c=%random% %% 10
set /a d=%random% %% 10
set /a e=%random% %% 10
ren %1 %a%%b%%c%%d%%e%%2
This pair prepends to the name of each file in the target directory a
random, five-digit number, with exactly five digits. (Just using
%random% could result in shorter numbers with no leading zeros. I know
this implementation will be a bit wobbly-distributed, moduloing 0-32767
by 10 and all; so sue me. It seems to work well enough.)
The matching pair attempts to remove the first five characters from the
name of every file in the same directory, and consists of rand_rem.bat
and rrem1.bat. Of course, this means (barring pathologically long file
names) that running rand_add immediately followed by rand_rem, should
have no net effect.
rand_rem.bat
for %%x in (c:\sharing\working4\*) do rrem1 "%%x" "%%~nx%%~xx"
rrem1.bat
set x=%2
ren %1 "%x:~6%
Unfortunately, it doesn't work correctly. It seems that some of the
files get renamed, then picked up by the "for" under the new name and
renamed again. Sometimes a file gets several multiples of five
characters stripped from the beginning of its name.
I was able to get this far with set /?, for /?, and Google, but now I
seem to be stymied. I don't see any obvious way to make rand_rem's for
ignore new file names -- or any obvious reason why it sometimes sees
the same file repeatedly under successive names, whereas that in
rand_add works as intended, for that matter. (Shouldn't they either
both work or both have the same bug?)
It's not clear from various Google searches and for /? how to make this
work, short of creating a whole extra directory for every file to be
moved to, then back from, which seems woefully inefficient (and if that
directory then gets used for anything else, will cause problems of its
own).
Any suggestions?
There are four -- two I've gotten working, and two with a problem.
First two are:
rand_add.bat
for %%x in (c:\a_particular_path\*) do radd1 "%%x" "%%~nx%%~xx"
radd1.bat
set /a a=%random% %% 10
set /a b=%random% %% 10
set /a c=%random% %% 10
set /a d=%random% %% 10
set /a e=%random% %% 10
ren %1 %a%%b%%c%%d%%e%%2
This pair prepends to the name of each file in the target directory a
random, five-digit number, with exactly five digits. (Just using
%random% could result in shorter numbers with no leading zeros. I know
this implementation will be a bit wobbly-distributed, moduloing 0-32767
by 10 and all; so sue me. It seems to work well enough.)
The matching pair attempts to remove the first five characters from the
name of every file in the same directory, and consists of rand_rem.bat
and rrem1.bat. Of course, this means (barring pathologically long file
names) that running rand_add immediately followed by rand_rem, should
have no net effect.
rand_rem.bat
for %%x in (c:\sharing\working4\*) do rrem1 "%%x" "%%~nx%%~xx"
rrem1.bat
set x=%2
ren %1 "%x:~6%
Unfortunately, it doesn't work correctly. It seems that some of the
files get renamed, then picked up by the "for" under the new name and
renamed again. Sometimes a file gets several multiples of five
characters stripped from the beginning of its name.
I was able to get this far with set /?, for /?, and Google, but now I
seem to be stymied. I don't see any obvious way to make rand_rem's for
ignore new file names -- or any obvious reason why it sometimes sees
the same file repeatedly under successive names, whereas that in
rand_add works as intended, for that matter. (Shouldn't they either
both work or both have the same bug?)
It's not clear from various Google searches and for /? how to make this
work, short of creating a whole extra directory for every file to be
moved to, then back from, which seems woefully inefficient (and if that
directory then gets used for anything else, will cause problems of its
own).
Any suggestions?