Page 1 of 2

can a dos script be created to do this??

Posted: Thu 03 Apr 2014 10:57 am
by ace2
OK, the background.
3500 jpg's created between 6am -9pm with Frame number as name.
I want to be able to copy jpg's between 7am -9am based on windows time stamp and repeat this 10am-12pm, 1pm-3pm & 4pm-6pm.

Is this at all possible?

I know there is some script kings out there...... :D

Re: can a dos script be created to do this??

Posted: Thu 03 Apr 2014 3:19 pm
by mcrossley
This should get you started...

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem get the filename and creation time
for /f "tokens=2,4 skip=5" %%a in ('dir "*" /a-D /tC') do (
	echo checking file %%b
	rem now split the time, and get the hour
	for /f "tokens=1 delims=:" %%h in ("%%a") do (
		rem compare the hour
		if %%h EQU 07 echo 'copy %%b somewhere79\%%b'
		if %%h EQU 08 echo 'copy %%b somewhere79\%%b'
		if %%h EQU 09 echo 'copy %%b somewhere79\%%b'
		if %%h EQU 10 echo 'copy %%b somewhere1012\%%b'
		if %%h EQU 11 echo 'copy %%b somewhere1012\%%b'
		if %%h EQU 12 echo 'copy %%b somewhere1012\%%b'
	)
)
You have to remove the echo on the copy obviously, and you could change the dir "*" to dir "*.jpg" or something. Written on Windows 7 with UK locale.

Edit: I had used forward slashes in the echos - changed to Windows back slashes.

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 12:37 am
by ace2
I can't seem to get that script working right.
It attempts to copy the file size instead of name.

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem get the filename and creation time
for /f "tokens=2,4 skip=5" %%a in ('dir "e:\snap\*.jpg" /a-D /tC') do (
   echo checking file %%b
   rem now split the time, and get the hour
   for /f "tokens=1 delims=:" %%h in ("%%a") do (
      rem compare the hour
      if %%h EQU 07 copy %%b "E:\output\%%b"
      if %%h EQU 08 copy %%b "E:\output1\%%b"
      if %%h EQU 09 copy %%b "E:\output2\%%b"
      if %%h EQU 10 copy %%b "E:\output3\%%b"
      if %%h EQU 11 copy %%b 'E:\output4\%%b"
      if %%h EQU 12 copy %%b "E:\output5\%%b"
   )
)
which is coming up with unable to find file specifies..

screen shot included
Image

The top section is without echo.
with echo on you can see it's using the file size as output name.

Any idea with this???

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 8:35 am
by gluepack
It's only a guess but is there a null field between time and size (would be <dir> for a folder) so should you be picking up 2 and 5 as opposed to 2 and 4. Also, based on your op, I think your time selection is incorrect.

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 8:58 am
by mcrossley
You need to check what the output from your dir /a-D /tC command looks like. Mine is like this...

Code: Select all

 Volume in drive C is PC COE
 Volume Serial Number is 7C55-333E

 Directory of C:\Users\user1

16/01/2014  09:53         5,242,880 NTUSER.DAT
16/01/2014  09:53           262,144 ntuser.dat.LOG1
So it starts with 5 lines of no interest to us, hence "skip=5"
The date is in field 1
The time in field 2
Filesize in field 3
and filename in field 4

So we want tokens 2 & 4 placed in variables %%a & %%b

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 9:12 am
by ace2
I would have thought mine been a windows 7 machine would be the same.
I did test it on a business machine while at work, so I'll try it on my windows 7 and windows 8 machine once I get home!
I would have thought mine been a windows 7 machine would be the same.
I did test it on a business machine while at wor k, so I'll try it on my windows 7 and windows 8 machine once I get home!

Since I only require time I would change to

Code: Select all

.   For /f "tokens=2 skip=5" %%a in ('dir "e:\snap\*.jpg" /a-D /tC') do (
   echo checking file %%b
   rem now split the time, and get the hour
   for /f "tokens=1 delims=:"%%a")

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 9:45 am
by mcrossley
ace2 wrote:Since I only require time I would change to

Code: Select all

.   For /f "tokens=2 skip=5" %%a in ('dir "e:\snap\*.jpg" /a-D /tC') do (
   echo checking file %%b
   rem now split the time, and get the hour
   for /f "tokens=1 delims=:"%%a")
No, you also require the file name, or how else do you know what to copy?
There is a typo in your code, the %%a should be outside the for options quotes.

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 9:50 am
by ace2
OK got it....(poor editing of message on phone lost the "")

Just have to figure out why the original code wouldn't work by checking what field are displayed with a dir

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 3:37 pm
by ace2
still at a slight loss with this, i've edited to what was needed 2 and 5(4 was dir name)
with the below script it copies the first 7 to output 3 then nothing else

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem get the filename and creation time
for /f "tokens=2,5 skip=8" %%a in ('dir "E:\snap" /a-D /tC') do (
   echo checking file %%b
   rem now split the time, and get the hour
   
for /f "tokens=1 delims=:" %%h in ("%%a") do (
      rem compare the hour
      if %%h EQU 06 copy E:\snap\%%b E:\output\%%b
      if %%h EQU 07 copy E:\snap\%%b E:\output1\%%b
      if %%h EQU 08 copy E:\snap\%%b E:\output2\%%b
      if %%h EQU 09 copy E:\snap\%%b E:\output3\%%b
      if %%h EQU 10 copy E:\snap\%%b E:\output4\%%b
      if %%h EQU 11 copy E:\snap\ %%b E:\output5\%%b )
   )
)
screen shot Image

source files
Image

Any help from the coding gods would be great...

Re: can a dos script be created to do this??

Posted: Fri 04 Apr 2014 4:42 pm
by mcrossley
Lets try and get some diagnostics by outputting what it thinks the creation 'hour' is for each file...

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem get the filename and creation time
for /f "tokens=2,5 skip=8" %%a in ('dir "E:\snap" /a-D /tC') do (
   rem now split the time, and get the hour
for /f "tokens=1 delims=:" %%h in ("%%a") do (
      echo checking file: %%b time: %%h
      rem compare the hour
      if %%h EQU 06 copy E:\snap\%%b E:\output\%%b
      if %%h EQU 07 copy E:\snap\%%b E:\output1\%%b
      if %%h EQU 08 copy E:\snap\%%b E:\output2\%%b
      if %%h EQU 09 copy E:\snap\%%b E:\output3\%%b
      if %%h EQU 10 copy E:\snap\%%b E:\output4\%%b
      if %%h EQU 11 copy E:\snap\ %%b E:\output5\%%b )
   )
)
It also seems to be missing the first file, does your dir actually have 8 lines of text before the file list, or 7?

Re: can a dos script be created to do this??

Posted: Sat 05 Apr 2014 12:31 am
by ace2
sorry i had it 7 before but wanted to skip the first file when i changed the folder from *.jpg to folder..

anyway instead of typing everything and a picture is worth a thousand words, where it is :

Image

Re: can a dos script be created to do this??

Posted: Sat 05 Apr 2014 1:30 am
by ace2
add region display setting jpg in case that has a effect as well

Image

Re: can a dos script be created to do this??

Posted: Sat 05 Apr 2014 9:08 am
by mcrossley
OK I see why you have to use field 5, you are using a 12 hour time format with am/pm indicator making an additional field 3. This also means he script will not work correctly anyway, the files created the same hours am and pm will be copied to the same destination. It will need reworking to fix this. I'm on a tablet at the more so it will have to be later, 24 hour times are much easier to work with ;)

Your directory listings do not appear to from the same cmd used by the script. The script uses the /a-D parameter to suppress directories, your listings include directories. Also on the explorer view it would be helpful if you added the file creation time column.

I have no idea where the script is getting what should be hours from, the numbers do not correlate with anything I can see on the screen shots.

Please confirm what OS this is running on.

Re: can a dos script be created to do this??

Posted: Sat 05 Apr 2014 9:39 am
by ace2
This one is winDoze 8 and the other one it'll be running on is winDoze 7.
Will put up a screen shot once I'm at home.

And thanks for helping with this

Re: can a dos script be created to do this??

Posted: Sat 05 Apr 2014 12:12 pm
by mcrossley
Untested as I haven't fiddled with my locale settings to change the time formats to 12hr, but it should cope with the case where there are duplicate hours am and pm...

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem get the filename and creation time
rem output: dd/mm/yyyy hh:mm AM|PM    9,999,999 FILENAME.EXT
for /f "tokens=2,3,5 skip=7" %%a in ('dir "E:\snap" /a-D /tC') do (
  rem now split the time, and get the hour
  for /f "tokens=1 delims=:" %%h in ("%%a") do (
    echo checking file: %%b time: %%a hour: %%h  am/pm: %%b
    rem is the file creation am or pm
    if /i %%b==AM (
      rem compare the morning hour
      if %%h==06 copy E:\snap\%%b E:\output1\%%b
      if %%h==07 copy E:\snap\%%b E:\output1\%%b
      if %%h==08 copy E:\snap\%%b E:\output1\%%b
      if %%h==09 copy E:\snap\%%b E:\output2\%%b
      if %%h==10 copy E:\snap\%%b E:\output2\%%b
      if %%h==11 copy E:\snap\%%b E:\output2\%%b
    ) else (
      rem compare the afternoon hour
      if %%h==12 copy E:\snap\%%b E:\output3\%%b 
      if %%h==01 copy E:\snap\%%b E:\output3\%%b 
      if %%h==02 copy E:\snap\%%b E:\output3\%%b 
      if %%h==03 copy E:\snap\%%b E:\output3\%%b 
      if %%h==04 copy E:\snap\%%b E:\output4\%%b 
      if %%h==05 copy E:\snap\%%b E:\output4\%%b 
      if %%h==06 copy E:\snap\%%b E:\output4\%%b 
    )
  )
)