Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a folder with files named like this:
20061211efo_s_web.jpg
20061212psf_s_web.jpg
20061213efs_s_web.jpgI need a batch file that will look at the date in the filename, and pull the file with the current system date, and move it to another folder.
Is there a way to make DOS look for the system date in the filename like that? I can do it using an automation program called Robotask, but I'd rather do a batch file if I can.
I'm using WinXP Pro, and cmd.exe

"pull the file with the current system date, and move it to another folder."
What do you mean by this?
"Computer security." — Oxymoron

If you use the 'current' system date, you will always have to run the program 'today' or the file date would never match. A better solution would be to input the desired date.
I use a compiled BASIC program to move e-mail attachments to a dated folder. The program makes a directory listing, reads it, moves files with selected extensions into a folder. Creates the folder as necessary.

:: move JPDs with names beginning with today's YYYYMMDD
@echo off
setLocal EnableDelayedExpansioncall :sub1
echo move %YYYY%%MM%%DD%*.jpg d:\some\other\place
goto :eof:sub1
:: get sys YMD into vars:: YYYY getter
> syyyy.d echo a 100
>> syyyy.d echo mov ah,2a
>> syyyy.d echo int 21
>> syyyy.d echo.
>> syyyy.d echo p=100 2
>> syyyy.d echo n sizeYYYY
>> syyyy.d echo w
>> syyyy.d echo q
debug < syyyy.d > nul
:: OK:: MM getter
> sMM.d echo a 100
>> sMM.d echo mov ah,2a
>> sMM.d echo int 21
>> sMM.d echo mov cx,0
>> sMM.d echo mov cl,dh
>> sMM.d echo.
>> sMM.d echo p=100 4
>> sMM.d echo n sizeMM
>> sMM.d echo w
>> sMM.d echo q
debug < sMM.d > nul
:: OK:: DD getter
> sDD.d echo a 100
>> sDD.d echo mov ah,2a
>> sDD.d echo int 21
>> sDD.d echo mov cx,0
>> sDD.d echo mov cl,dl
>> sDD.d echo.
>> sDD.d echo p=100 4
>> sDD.d echo n sizeDD
>> sDD.d echo w
>> sDD.d echo q
debug < sDD.d > nul
:: OK
del *.dfor %%F in (sizeYYYY sizeMM sizeDD) do call :sub1 %%F
set /p YYYY=<sizeYYYY.#
set /p MM=<sizeMM.#
if %MM% LSS 10 set MM=0%MM%
set /p DD=<sizeDD.#
if %DD% LSS 10 set DD=0%DD%
del size*.*
echo YYYYMMDD=%YYYY%%MM%%DD%
goto :eof:sub1
> %1.# echo %~z1
goto :eof
=====================================
If at first you don't succeed, you're about average.M2

Hey M2, I remember another script very similar to this a while ago.
What does the Assembly do in your script?
"Computer security." — Oxymoron

Hi tony,
It uses int 21 function 2a to get system date. YYYY goes into cx. MM & DD get put into cl from dh & dl, respectively.
cx holds the size of file to write. Then CMD gets the file size into the needed vars.
=====================================
If at first you don't succeed, you're about average.M2

Lol, ok. I should get a good book on ASM. Maybe then I would understand a bit more.
"Computer security." — Oxymoron

Hi tony,
If it makes you feel any better, it took over 20 hours to figure out that scrap. It could be cleaned up considerably. But by the time I got it to 'work' I was fried.
LOLGetting DATEs into vars is a piece of cake IF you know the layout. I think you've been in a few threads where some joker said 'just' md %DATE%
=====================================
If at first you don't succeed, you're about average.M2

"some joker said 'just' md %DATE%"
That is funny. I remember someone saying that. Obviously they don't test their scripts before posting them. ;-)
"Computer security." — Oxymoron

ow, thanks for all your help. Alas, I'm getting error messages and the files aren't transferring. Here's the error:
The system cannot find the file specified
The system cannot find the file specified
The syntax of the command is incorrect.
10 was unexpected at this time.I'm afraid I'm only experienced with basic DOS commands, so all the stuff you did is greekish to me. So, any help is very kind.
Thanks.

You should use the write tool for the job. Even though it can be done with a batch file, it would be better/easier to use a 3rd party utility designed for this purpose. You already know about Robotask, but here's a Perl script as another option.
#!perl
use POSIX qw/strftime/;
use File::Copy;my $src_dir = 'c:/source/dir';
my $dest_dir = 'd:/destination/dir';
my $date = strftime("%Y%m%d", localtime);while(my $file = <$src_dir/$date*_web.jpg>) {
    move($file, $dest_dir);
}

FYI, it took 5 minutes to work that up, which included 4 minutes of indecision on whether I should use the variables or hard code the paths. If we hard code the paths and do a system call instead of using the copy module, we can reduce it to 3 lines. :)
==============================================================
This may need a little tweek on the system call, but you get the picture.
use POSIX qw/strftime/;
my $date = strftime("%Y%m%d", localtime);
while (<c:/source/dir/$date*_web.jpg>) { system ("move $_ d:\\destination\\dir"); }

"The system cannot find the file specified"
Do this and post the result:
dir/b 2006*.jpg
=====================================
If at first you don't succeed, you're about average.M2

Here is the result of dir /b 2006*jpg
20061213adf_s_web.jpg
20061214ads_s_web.jpg
20061215efo_s_web.jpg
20061216eds_s_web.jpg
20061218efo_s_web.jpg
20061219efd_s_web.jpg
20061220efa_s_web.jpg

FishMonger,
I've never used Perl, isn't that for web sites?
I noticed your script has /'s and not \'s
Thanks.

AngusYoung,
You're with ACDC, right?
[1] perl is for any regex job. FM is the man to see.
[2] How did you get the BATCH sorted out?
=====================================
If at first you don't succeed, you're about average.M2

Yep, AC/DC is correct. We aren't touring right now, so I'm back to my day job.
I'm still in limbo right now. The Perl script FM gave me doesn't give me any errors, but at the same time doesn't do anything. I installed ActivePerl and I can run other perl scripts...
The batch file still gives me the error I posted before.

I don't know how the JPGs can show in a DIR and be not found by the BAT.
=====================================
If at first you don't succeed, you're about average.M2

I've added the printing of a status message when the file is moved. Normally I'd add additional error handling, but this is just an example script.
=================================================
C:\testing>type angus.pl
#!perluse POSIX qw/strftime/;
use File::Copy;my $src_dir = 'c:/testing';
my $dest_dir = 'c:/temp';
my $date = strftime("%Y%m%d", localtime);while(my $file = <$src_dir/$date*_web.jpg>) {
print "moving $file to $dest_dir dir\n";
move($file, $dest_dir);
}C:\testing>dir /b *.jpg
20061213adf_s_web.jpg
20061214ads_s_web.jpg
20061215efo_s_web.jpg
20061216eds_s_web.jpg
20061218efo_s_web.jpg
20061219edf_s_web.jpg
20061220efa_s_web.jpgC:\testing>dir /b c:\temp\*.jpg
File Not FoundC:\testing>angus.pl
moving c:/testing/20061215efo_s_web.jpg to c:/temp dirC:\testing>dir /b *.jpg
20061213adf_s_web.jpg
20061214ads_s_web.jpg
20061216eds_s_web.jpg
20061218efo_s_web.jpg
20061219edf_s_web.jpg
20061220efa_s_web.jpgC:\testing>dir /b c:\temp\*.jpg
20061215efo_s_web.jpg

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |