Batch file commands - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Batch file commands

milanesemilanese Posts: 1Member
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: est

COPY "D:New_Files*.dat" "D: est*.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

Comments

  • PatrickMc2008PatrickMc2008 Posts: 11Member
    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.

    [u][b]METHOD 1 - File Name[/b][/u]
    [code]# 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: est"
    endif
    done[/code]



    [u][b]METHOD 2 - File Creation Time[/b][/u]
    [code]# 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: est"
    done[/code]




    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.

    [code]script "C:/Scripts/CopyButToday.txt"[/code]

    That would do it.

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




  • buluosmbuluosm Posts: 1Member
    Good ,thanks a lot.
Sign In or Register to comment.