MS-DOS

Moderators: blip
Number of threads: 389
Number of posts: 904

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Batch file commands Posted by milanese on 15 Dec 2009 at 8:49 AM
Hi,
I am very new when it comes to batch files and I need to copy some files from a directory to another on a windows 2003 server.
I have writeen a simple batch file which looks like this:

@echo off
SET Day=%date:~0,2%
SET Month=%date:~3,2%
SET Year=%date:~6,4%
SET cdate=%Year%%Month%%Day%

SET localDir=D:\New_Files
SET newDir=D:\test

COPY "D:\New_Files\*.dat" "D:\test\*.dat"

pause
rem dir c:\windows

This is all work, bt the problem I am having is that I only need to copy across files whose date is in the past, i.e.:
The list of files is this
a20091211.dat
a20091212.dat
b20091216.dat
c20091214.dat
c20091215.dat
e20091101.dat

Today is the 15th December 2009 and the file for today would like *20091215.dat. I need to copy all and only the files whose date is prior to today, so I should just move the below files:

a20091211.dat
a20091212.dat
c20091214.dat
e20091101.dat

I have searched high and low on the web and could not find anything: can you please advise on a solution or anywhere where I can find a way to do it?
Thanks
Report
Re: Batch file commands Posted by PatrickMc2008 on 17 Dec 2009 at 9:53 AM
I think you may need something in addition to DOS.

There are two ways to do this. One way is based on the file names, the other is based on file creation time.

METHOD 1 - File Name
# Script CopyButToday.txt
var str today, filelist, file
# Get today's date
set $today = gettime()
chex "8]" $today > $today
# Collect a list of all *.dat files in D:\New_Files.
lf -n "*.dat" "D:\New_Files" > $filelist
while ($filelist <> "")
do
    lex "1" $filelist > $file
    # Does this file have $today in its name ?
    if ( { sen ("^"+$today+"^") $file } <= 0 )
        # No file does not have $today in the name.
        # Copy this file.
        system copy ("\""+$file+"\"") "D:\test"
    endif
done




METHOD 2 - File Creation Time
# Script CopyButToday.txt
var str today, filelist, file
# Get today's date
set $today = gettime()
chex "8]" $today > $today
# Collect a list of all *.dat files in D:\New_Files
# that have been created before $today
lf -n "*.dat" "D:\New_Files" ($fctime < $today) > $filelist
while ($filelist <> "")
do
    lex "1" $filelist > $file
    # Copy this file.
    system copy ("\""+$file+"\"") "D:\test"
done





Both scripts are in biterscripting ( http://www.biterscripting.com ). Whichever method you choose, save the script in file C:/Scripts/CopyButToday.txt, start biterscripting, and enter the following command.

script "C:/Scripts/CopyButToday.txt"


That would do it.

If you make the scripts even fancier, please post them for others.




Report
Re: Batch file commands Posted by buluosm on 21 Jan 2010 at 12:56 PM
Good ,thanks a lot.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.