move stroke sequential rename

Microsoft Windows xp tablet pc edition 2...
February 22, 2010 at 15:16:50
Specs: Windows Vista
hello everyone,

i need some help, i'm trying to write a
batch/cmd file to copy files from a removable
dvr, so far i have spent about 5 hours cursing
at my laptop with no luck, i'm hoping some
one will be able to give me a hand.

ok, heres what i'm aiming for. i have a small
drv mounted in my 4x4 for recording and a
tablet pc in a sealed case, the dvr charges
from the usb but when the usb is plugged into
pc acts only in file access mode.

so i'm going to put a switch in the usb data
line to switch between charge/file access

i wish to place a autorun file on he flash card
to run a batch on connection. to copy the files
sequentially into a directory on pc

i want the batch to first check for a directory
called "vids" in the root c:\ and if it doesnt
exist create it, i have sorted code for this.



i then want the batch file to count the number
of files on the dvr
set ext=.avi
for /F %%a in ('dir /b/a-d-h ^| find /c "%ext%"')
do set cam=%%a

seams to work for this when run from the
same directory as files, but i can't get it to
work for vids directory.

i can get it to work by
set folder=C:\VIDS
for /f "tokens=1" %%f in ('dir
"%folder%\*.*"^|findstr /c:" File(s)"') do set

its from here on i'm really stuck, once the
program has worked out the start number for
the files (number of files in vids dir +1) i want it
to rename and move the avi files from the dvr
to the vids directory in sequential format ie:
001, 002, 003, etc

i found this copy for naming but again i'm
struggling to get it working
set N=0
for /f "tokens=* %%a in ('dir /b *.jpg') do (
set /a N+=1
if !N! LSS 1000 set S=!N!
if !N! LSS 100 set S=0!N!
if !N! LSS 10 set S=00!N!
rename "%%a" !S!.avi

xing fingers somone can help me with this

cheers, Jon

See More: move stroke sequential rename

Report •

February 22, 2010 at 16:12:59
here's a good trick for that, courtesy of Razor i think:
just make "4" into whatever length you want the numbers to be, and the number of zeros doesn't matter as long as there's enough of them to give you the length you're looking for
set /a num=%count%
pushd %folder%\jpgfiles
for %%a in (*.jpg) do (
set file=%%a
call :mv
goto :eof
set /a num+=1
set name=00000%num%
:: this makes numbers like: 0001 0012 0256 9999
set name=%name:~-4%
echo moving %file% to c:\vids\%name%.avi
move %1 c:\vids\%name%.avi
goto :eof

not tested, but it gives you the idea...

Report •

February 23, 2010 at 02:35:16
I like the code (and as mentioned in a similar question) the week point is numbers above the max. you are setting, in casu : 9999

If you get past this number, it'll behave buggy, no ?

And second question, what if the target-file already exists ?

And a third question, are you renaming JPG's to AVI's ?

Report •

February 23, 2010 at 03:15:01
thank you for your reply, i've had a play about but still no joy,
i'm guessing the "count" was to collect the number of files
allready in c:\vids?? then +1 so if 0001,0002,0003 allready
exist then the next file would be number of files "3" + 1 so is
would be 0004?.

i commented out the line pushd %folder% as this makes it
work from vids directory not the file source.

it seams to run properly but no file movement :( for the
purpose of testing i'm working from
c:\cam\ 'contains script and files to be renamed/moved'
and c:\vids 'allready contains 0001.avi 0002.avi 0003.avi

as the device the files been copyied from will be a usb drive
it's drive letter is subject to change so i need to run batch
from the drive

i'll probably create a date named sub directory eventually but
thought out a day the drive may be purged of files numerous
times hence the reason for adding sequentially to the existing
files. this i'll add later as the code seams pretty straight

thank you so much for the help, the last time i played with
batch scripts was back in the dos 6.22 days :o

heres what i have so far:

set folder=C:\VIDS
for /f "tokens=1" %%f in ('dir "%folder%\*.*"^|findstr /c:"
File(s)"') do set count=%%f

set /a num=%count%
::pushd %folder%
for %%a in (*.avi) do (set file=%%a call :mv)
goto :eof

set /a num+=1
set name=00000%num%
:: this makes numbers like: 0001 0012 0256 9999
set name=%name:~-4%
echo moving %file% to c:\vids\%name%.avi
move %1 c:\vids\%name%.avi
goto :eof

Report •

Related Solutions

February 23, 2010 at 03:21:30
i also forgot to mention, although the script is destined to be
used on a tablet pc running xp tablet, for obvious reasons i'm
writing and testing on a vista laptop, not sure if this could be
causing any issues.

Report •

February 25, 2010 at 14:30:57
anyone able to give me any more pointers on this please??, its
really starting to bug me now :(

is there any way to step though a script to debug it??

Report •

February 25, 2010 at 15:19:57
i screwed up in :mv, very sorry about that. here is what it should be:
(hell, i'll just re-post the whole thing as there's a couple other issues):
set folder=C:\VIDS
:: suggest change *.* to *.avi in foll. in case other files in the dir.
for /f "tokens=1" %%f in ('dir "%folder%\*.avi"^|findstr /c:"
File(s)"') do set count=%%f
:: added an echo - no reason to pause if not for debugging
echo count: %count%

set /a num=%count%
:: this "don't look right", not build right. fixing it:
for %%a in (*.avi) do (
set file=%%a
call :mv
goto :eof

set /a num+=1
set name=00000%num%
:: this makes numbers like: 0001 0012 0256 9999
set name=%name:~-4%
echo moving %file% to c:\vids\%name%.avi
:: here was the screweup. change %1 to %file%
move %file% c:\vids\%name%.avi
goto :eof

i don't know how or where i came up with %1, that had nothing to do with what you're doing. I guess not enough coffee. my bad!
if it doesn't run right, try adding some other echos+pauses, and another trick is to try problematic commands directly from the commandline to see what they do (always remembering to cut the %% down to % on for-loop var.s)
another debug is to disable "echo off", but it can get kind of confusing on the screen.
hope this helps you.

Report •

February 25, 2010 at 15:49:23
thank you so much :), it works perfectly :)

Report •

Ask Question