Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Allen, Texas, USA
    Posts
    727
    Thanks
    1
    Thanked 0 Times in 0 Posts

    xcopy bat file help

    I have a task that requires me to copy files to another directory based on certain criteria on the 1st of each month.
    The criteria is that it needs to copy files from a directory that start with a particular word and are only an xls file. I can figure out half of that, but with the *.xls, but unclear as to how to copy only those as well too that start with a particular word. As an example I need to copy all files that start with the word "Deposit" and are only an .xls file.

    Part two of this task is this bat file needs to run only on the 1st of the month. I think the best way would be to simply create a Task Schedule to run on each of those days. The issue is that I need to create one for each month as each month requires those files to be put into a different folder. Not sure if there are any special answers to that besides creating 12 bat files and 12 Task Schedules.

    Now the fun part...is there a way to have my computer notify me that this process bat file actually completed and the result and/or if failed? It's imperative that this run whether I'm at the computer or not.

    Thanks!

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    kzkz,

    That would be: deposit*.xls

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,396
    Thanks
    445
    Thanked 404 Times in 376 Posts
    RG posted before I finished typing, but here's what I typed:

    To limit your copy to include only the files that start with the word "Deposit" and are only .xls files, specify the name as deposit*.xls (i.e put the asterisk after the first part).

    I think Task Scheduler is your best bet to get it to run on a particular day.

    In your batch file, on the line after the xcopy command, you can put "IF ERRORLEVEL ___" to determine the next step if there is a failure of the command to execute. Or, put "IF ERRORLEVEL 0" which would indicate success (i.e. if not errorlevel 0, then there is an error of some kind).

    There is a very good explanation of all of this on the Microsoft web site:

    https://www.microsoft.com/resources/....mspx?mfr=true

    In the example on the Microsoft web site, you will see the following:

    xcopy %1 %2

    What that means is that when you ran the batch file, you had two additional entries (parameters) on the command line. In other words, if the batch file name is copyfiles.bat, you might have typed in a command that was something like this:

    copyfiles c:\deposits f:\

    This means that the batch file would treat %1 as "c:\deposits" and %2 as "f:\". In other words, you could specify the source and target locations on the command line when you run your batch file. Or you could put the first part of the name:

    copyfiles deposits

    It would then treat %1 as "deposits". You could then put the following in your batch file: "%1*.xls" (in other words, "deposits*.xls"), thereby allowing you to simply type whatever you want on the command line as the first part of the name, and the batch file would then use that as the first part of the filename.

    Boy, this brings back lots of memories! Those were the days!
    Last edited by mrjimphelps; 2014-04-22 at 18:35.

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Allen, Texas, USA
    Posts
    727
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you both. It's funny as I was trying to figure that out it wasn't working because I had the wrong file name. The above you both listed works great. I've already got the batch file created now for the xcopy. That wasn't too hard.
    Task Scheduler will work perfectly.

    What I'm looking for is not a visual display on my pc if the copy worked or didn't but an actual email to be sent that told me that it completed or failed. Is that possible? I want this to be totally hands off each and every month, but for it to simply notify me offset if completed or failed.

    KZ

  5. #5
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,413
    Thanks
    33
    Thanked 195 Times in 175 Posts
    You could be looking for a program like BLAT to generate an email, but I haven't used this for at least ten years. AntiVirus programs don't like people creating emails from within programs, so I don't know whether it would still work for your system...
    BATcher

    Time prevents everything happening all at once...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •