Computing.Net > Forums > Programming > Batch to move file by sysdate

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch to move file by sysdate

Reply to Message Icon

Name: AngusYoung
Date: December 12, 2006 at 13:55:30 Pacific
OS: Win XP Pro
CPU/Ram: Pentium M - 1.5 GB
Product: Dell
Comment:

I have a folder with files named like this:

20061211efo_s_web.jpg
20061212psf_s_web.jpg
20061213efs_s_web.jpg

I 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



Sponsored Link
Ads by Google

Response Number 1
Name: tonysathre
Date: December 12, 2006 at 14:33:13 Pacific
Reply:

"pull the file with the current system date, and move it to another folder."

What do you mean by this?

"Computer security." — Oxymoron


0

Response Number 2
Name: wizard-fred
Date: December 12, 2006 at 23:46:33 Pacific
Reply:

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.


0

Response Number 3
Name: Mechanix2Go
Date: December 12, 2006 at 23:58:13 Pacific
Reply:

:: move JPDs with names beginning with today's YYYYMMDD

@echo off
setLocal EnableDelayedExpansion

call :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 *.d

for %%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



0

Response Number 4
Name: tonysathre
Date: December 13, 2006 at 00:38:14 Pacific
Reply:

Hey M2, I remember another script very similar to this a while ago.

What does the Assembly do in your script?

"Computer security." — Oxymoron


0

Response Number 5
Name: Mechanix2Go
Date: December 13, 2006 at 02:24:46 Pacific
Reply:

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



0

Related Posts

See More



Response Number 6
Name: tonysathre
Date: December 13, 2006 at 03:03:41 Pacific
Reply:

Lol, ok. I should get a good book on ASM. Maybe then I would understand a bit more.

"Computer security." — Oxymoron


0

Response Number 7
Name: Mechanix2Go
Date: December 13, 2006 at 03:43:29 Pacific
Reply:

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.
LOL

Getting 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



0

Response Number 8
Name: tonysathre
Date: December 13, 2006 at 04:21:01 Pacific
Reply:

"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


0

Response Number 9
Name: AngusYoung
Date: December 13, 2006 at 19:37:00 Pacific
Reply:

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.


0

Response Number 10
Name: FishMonger
Date: December 13, 2006 at 22:04:59 Pacific
Reply:

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);
}


0

Response Number 11
Name: FishMonger
Date: December 13, 2006 at 22:23:35 Pacific
Reply:

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"); }



0

Response Number 12
Name: Mechanix2Go
Date: December 14, 2006 at 00:34:20 Pacific
Reply:

"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



0

Response Number 13
Name: AngusYoung
Date: December 15, 2006 at 09:09:18 Pacific
Reply:

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


0

Response Number 14
Name: AngusYoung
Date: December 15, 2006 at 09:46:48 Pacific
Reply:

FishMonger,

I've never used Perl, isn't that for web sites?

I noticed your script has /'s and not \'s

Thanks.


0

Response Number 15
Name: AngusYoung
Date: December 15, 2006 at 10:18:58 Pacific
Reply:

Fish,

Nevermind, I did some research and got the lowdown on Perl.


0

Response Number 16
Name: Mechanix2Go
Date: December 15, 2006 at 12:58:28 Pacific
Reply:

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



0

Response Number 17
Name: AngusYoung
Date: December 15, 2006 at 13:17:05 Pacific
Reply:

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.



0

Response Number 18
Name: Mechanix2Go
Date: December 15, 2006 at 13:48:12 Pacific
Reply:

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



0

Response Number 19
Name: FishMonger
Date: December 15, 2006 at 15:20:37 Pacific
Reply:

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
#!perl

use 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.jpg

C:\testing>dir /b c:\temp\*.jpg
File Not Found

C:\testing>angus.pl
moving c:/testing/20061215efo_s_web.jpg to c:/temp dir

C:\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.jpg

C:\testing>dir /b c:\temp\*.jpg
20061215efo_s_web.jpg



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch to move file by sysdate

Batch to move files www.computing.net/answers/programming/batch-to-move-files/15936.html

batch to move files with same names www.computing.net/answers/programming/batch-to-move-files-with-same-names/19261.html

Batch to move all files in a list. www.computing.net/answers/programming/batch-to-move-all-files-in-a-list/16817.html