• XCOPY batch file that takes its name from weekday (Windows XP)

    Home » Forums » AskWoody support » Windows » Windows Vista, XP and earlier » Questions: Vista, XP back to 3.1 » XCOPY batch file that takes its name from weekday (Windows XP)

    Author
    Topic
    #388345

    I would like to create a batch file that I can assign to an icon. that will copy a directory to another area of the hard drive and rename the directory with the name of the week and overwrite if an old one exists.
    for instance this monday when hit the icon would copy c:meddata to c: monday meddata, On Tuesday would copy to C:tuesday meddata etc. and the following tuesday would overwrite the old tuesday. Is this possible?? Like XCOPY and pick the name of the weekday.
    Jerome

    Viewing 2 reply threads
    Author
    Replies
    • #681464

      In a word, yes. A couple of things to consider:

      If you want to fully replace the date from last week, you should probably delete the old directory and then follow with the xcopy. Otherwise the directory will contain files from last week that don’t exist today.

      I don’t know of a direct source for the name of the day of the week. Simplest option would probably be to schedule a small task to run daily to either set an environment variable to the day (eg todayis=monday), or to create an empty file with the name (eg file monday in directory todayis), and then use that in your bat. There may also be an old dos utility that can do it in your bat.

    • #681466

      The problem with XP and BATch files is that DATE /T in some regional settings no longer gives you the day of the week. (In Geek Mode, I can give you the full list of the 83 or so possible Regional Settings, and which still do or don’t give the DoW!!).

      On my (UK) NT4 and W2K boxes at work, DATE /T would give “Sun 01/06/2003”,
      On my (UK) XP box at home, I get “01/06/2003”
      Have a look at your (US) XP box, and say what DATE /T gives you. I suspect it will be “Sun 06/01/2003”. If so, then it’s easy!

      Tim is right about the “delete directory before copy” problem; an alternative is to use ROBOCOPY from the XP Resource Kit, which will mirror one directory to another (among many other things) if asked, or XXCOPY, which does a very similar job.

      Here’s something which you may be able to use/build on…

      @echo off
      
      setlocal
      
      :: get today's DoW, assuming US settings "DoW mm/dd/yyyy"
      for /f "tokens=1" %%a in ('date /t') do set DoW=%%a
      ECHO Day-of-the-Week from DATE /T is  %DoW% & PAUSE
      
      :: tedious way of getting the full Day (more elegant ways are possible!)
      if "%DoW%"=="Mon" set day=Monday
      if "%DoW%"=="Tue" set day=Tuesday
      if "%DoW%"=="Wed" set day=Wednesday
      if "%DoW%"=="Thu" set day=Thursday
      if "%DoW%"=="Fri" set day=Friday
      if "%DoW%"=="Sat" set day=Saturday
      if "%DoW%"=="Sun" set day=Sunday
      ECHO Today's (full name) day is
      • #681477

        John:
        Wow this works perectly. Just what I wanted. Looks kind of complex to put together.
        Thanks a million
        Jerome

        • #681479

          It must be MY video, because I see some garbled characters in the post that, when I changed them to day worked just fine as put forth by John. I guess it must be me, since you didn’t mention a problem. Glad it does the trick!

          Added: Maybe it my “interface” to the Lounge, because when I tried to type the % character, I got the same as my attachment, here in this post….. Anyone know why? (Evidently, two % signs causes a problem!?)

      • #681482

        Not sure myself – there was a discussion about this many moons ago which I can’t immediately find, and more recently a similar oddity was discussed in this thread.

        Edited to add:

        Ah, it is beginning to come back to me…
        % is OK
        %d is OK
        but % da gives you

        • #681495

          So the question is: Why? and to what purpose? [Oh dear, that’s two questions!]

          I’m glad Jerome got what he wanted; it’s pretty straightforward doing this in a BATch file. Maybe we should have a forum devoted to Scripting? scratch

          • #763305

            [indent]


            Maybe we should have a forum devoted to Scripting? scratch


            [/indent]
            Perhaps – in the last 7 months – you’ve now found the Web Design, Coding & Scripting Board? grin

            • #763315

              When I read the title of that board, I think of web-related scripting, not batch files. shrug

            • #763321

              So did I – the first few times I looked at it. Isn’t this a bit like our discussion of whether a Win2K Server issue should be on the Win2K Board or the Servers Board? How about renaming it Coding, Scripting and Web Design? shrug

            • #763322

              So did I – the first few times I looked at it. Isn’t this a bit like our discussion of whether a Win2K Server issue should be on the Win2K Board or the Servers Board? How about renaming it Coding, Scripting and Web Design? shrug

            • #763316

              When I read the title of that board, I think of web-related scripting, not batch files. shrug

          • #763306

            [indent]


            Maybe we should have a forum devoted to Scripting? scratch


            [/indent]
            Perhaps – in the last 7 months – you’ve now found the Web Design, Coding & Scripting Board? grin

          • #763443

            Leif stated:


            Ah, it is beginning to come back to me…
            % is OK
            %d is OK
            but % da gives you

          • #763444

            Leif stated:


            Ah, it is beginning to come back to me…
            % is OK
            %d is OK
            but % da gives you

      • #763281

        John:
        I have been using this with great success till I upgraded to office 2003 which somehow affected windows XP. NOW I no longer get the day of the week. If I switch the regional settings to dddd, mm/dd/yyyy the batch works but it louse up microsoft money.
        Is there a way of drawing the day of the week from say the long date format of windows to get the day of the week, or do you have a newer solution??
        Thanks
        Jerome

        • #763313

          Jerome

          I don’t have Server 2003 so I can’t give you an immediate answer. I can derive the DoW from the date via a devious method, but having been off for nearly three weeks, my Inbox contains just under 1000 messages, at least 90% of which Spam, so I won’t get a chance to look today. But I will get back to you by/on Monday…

          In the interim, can you please tell me what you get from DATE /T in a Command Prompt window, with the Short Date settings at the default values? Thanks. (I presume mm/dd/yyyy rather than DoW mm/dd/yyyy )

        • #763314

          Jerome

          I don’t have Server 2003 so I can’t give you an immediate answer. I can derive the DoW from the date via a devious method, but having been off for nearly three weeks, my Inbox contains just under 1000 messages, at least 90% of which Spam, so I won’t get a chance to look today. But I will get back to you by/on Monday…

          In the interim, can you please tell me what you get from DATE /T in a Command Prompt window, with the Short Date settings at the default values? Thanks. (I presume mm/dd/yyyy rather than DoW mm/dd/yyyy )

        • #763338

          Jerome

          Heck, why should I redo the work since Ritchie Lawrence has already done it all? grin (Go through “Batch Function Library” to “Date and Time Functions” to “DateToDoW”)

          If you have any trouble with the three functions he’s calling, just let me know and I’ll combine them into a single chunk of BATch code for you.

          • #763350

            John:
            I looked at the site, but it was too complex for me. I would very much appreciate it if you could combine it into the batch file that you wrote for me originally as it worked so well for me. Welcome back and Thanks.
            Jerome
            @echo off

            setlocal

            :: get today’s DoW, assuming US settings “DoW mm/dd/yyyy”
            for /f “tokens=1” %%a in (‘date /t’) do set DoW=%%a
            ECHO Day-of-the-Week from DATE /T is %DoW% & PAUSE

            :: tedious way of getting the full Day (more elegant ways are possible!)
            if “%DoW%”==”Mon” set day=Monday
            if “%DoW%”==”Tue” set day=Tuesday
            if “%DoW%”==”Wed” set day=Wednesday
            if “%DoW%”==”Thu” set day=Thursday
            if “%DoW%”==”Fri” set day=Friday
            if “%DoW%”==”Sat” set day=Saturday
            if “%DoW%”==”Sun” set day=Sunday
            ECHO Today’s (full name) day is

            • #763693

              Jerome

              I have produced two versions for you, one using Ritchie Lawrence-type Functions, and the other using in-line code.

              Since the Lounge is, at present, AGONISINGLY slow (and the clock is 1 hr 18 mins slow!), it would take too long to post them. Since the files are also a bit lengthy, I will try tomorrow to send you a Private Message with them in, otherwise, if it’s STILL slow, could you let me have an email address in a private message so that I can send them in ZIPped form on Monday. That would also get over the % d a problem we have…

            • #763723

              When you do get a chance to get back online – given the treacle-like performance smile – could you perhaps include the code as an attachment to your last post?

            • #763759

              Unkamunka

              We have engaged in extensive correspondence and testing – see the TXT attachment – good idea of yours, rather than getting it reformatted / % day’ed as part of the message.

              If anyone is sufficiently interested to need an explanation of any part, please let me know! The “Stage 1” determination of year/month/day works regardless of operating system (viz. NT, 2000, XP, 2003) and of regional/international setting – XP certainly now drops the Day-of-the-Week for some countries, like UK. No, I don’t know why…

            • #763760

              Unkamunka

              We have engaged in extensive correspondence and testing – see the TXT attachment – good idea of yours, rather than getting it reformatted / % day’ed as part of the message.

              If anyone is sufficiently interested to need an explanation of any part, please let me know! The “Stage 1” determination of year/month/day works regardless of operating system (viz. NT, 2000, XP, 2003) and of regional/international setting – XP certainly now drops the Day-of-the-Week for some countries, like UK. No, I don’t know why…

            • #763724

              When you do get a chance to get back online – given the treacle-like performance smile – could you perhaps include the code as an attachment to your last post?

            • #893387

              Dear John
              I love the batch files that you made up and use them every day to backup important directories in one fell swoop to have a quick backup for corruption and many days available of backups.
              However I am trying to add a line for the outlook.pst and xcopy just seems to ignore it. Maybe xcopy cannot handle a long name. ? use xcopy32 or some other fix.
              xcopy C:Documents and SettingsJerome R Klein MDLocal SettingsApplication DataMicrosoftOutlookoutlook4.pst “c:a

            • #893388

              Dear John
              I love the batch files that you made up and use them every day to backup important directories in one fell swoop to have a quick backup for corruption and many days available of backups.
              However I am trying to add a line for the outlook.pst and xcopy just seems to ignore it. Maybe xcopy cannot handle a long name. ? use xcopy32 or some other fix.
              xcopy C:Documents and SettingsJerome R Klein MDLocal SettingsApplication DataMicrosoftOutlookoutlook4.pst “c:a

            • #893401

              Just a short in the dark – try quotation marks around the source file name (“C:…pst”).

              Joe

              --Joe

            • #893475

              No unfortunately did not work
              Jerome

            • #893531

              Jerome

              I think Joe is right – if ever there’s a blank anywhere in a path, you MUST include the whole path in double-quotes. This applies equally to the source path as to the target path.

              You should end up with something like

              xcopy “C:Documents and SettingsJerome R Klein MDLocal SettingsApplication DataMicrosoftOutlookoutlook4.pst” “c:a

            • #893533

              John:
              I tried it again and added a pause as I wanted to see if there was an error message.
              The quotes helped but now it seems that outlook when it is running and even after exiting unless you also get rid of a background outlook.exe blocks the file transfer unless outlook is unloaded in every which way.

            • #893548

              Jerome

              Yes, sorry – I had forgotten that it wouldn’t (and, indeed, shouldn’t) copy the file if it was open. When you close Outlook down you shouldn’t be left with an outstanding EXE file. Does this happen a lot? If so, I can give you a way to kill it, but you would have to ensure that you close Outlook down first…

              John

            • #893577

              John:
              Today it seems to be working fine, yesterday when I was trying to get it to work it was doing it all the time, ie outlook really closes on close, go figure.
              Does your way of closing mean I can put in a line before the xcopy in the batch file to close any extra instances of outlook that may be open?
              Jerome

            • #893589

              Jerome

              I don’t have a way to distinguish between a “real” unclosed version of Outlook, and one left lying around for some unknown reason. It would not necessarily be a good idea to “kill” the former (rather, one should close it down cleanly), but wouldn’t matter much about the latter (which probably should not be present, anyway).

              As I said before, there should only be one copy of OUTLOOK.EXE in the Task manager -> processes list. Could you monitor this (click on the “Image Name”) column heading, and see how often you find two instances? Thanks!

              John

            • #893590

              Jerome

              I don’t have a way to distinguish between a “real” unclosed version of Outlook, and one left lying around for some unknown reason. It would not necessarily be a good idea to “kill” the former (rather, one should close it down cleanly), but wouldn’t matter much about the latter (which probably should not be present, anyway).

              As I said before, there should only be one copy of OUTLOOK.EXE in the Task manager -> processes list. Could you monitor this (click on the “Image Name”) column heading, and see how often you find two instances? Thanks!

              John

            • #893578

              John:
              Today it seems to be working fine, yesterday when I was trying to get it to work it was doing it all the time, ie outlook really closes on close, go figure.
              Does your way of closing mean I can put in a line before the xcopy in the batch file to close any extra instances of outlook that may be open?
              Jerome

            • #893549

              Jerome

              Yes, sorry – I had forgotten that it wouldn’t (and, indeed, shouldn’t) copy the file if it was open. When you close Outlook down you shouldn’t be left with an outstanding EXE file. Does this happen a lot? If so, I can give you a way to kill it, but you would have to ensure that you close Outlook down first…

              John

            • #893532

              Jerome

              I think Joe is right – if ever there’s a blank anywhere in a path, you MUST include the whole path in double-quotes. This applies equally to the source path as to the target path.

              You should end up with something like

              xcopy “C:Documents and SettingsJerome R Klein MDLocal SettingsApplication DataMicrosoftOutlookoutlook4.pst” “c:a

            • #893476

              No unfortunately did not work
              Jerome

            • #893402

              Just a short in the dark – try quotation marks around the source file name (“C:…pst”).

              Joe

              --Joe

            • #763694

              Jerome

              I have produced two versions for you, one using Ritchie Lawrence-type Functions, and the other using in-line code.

              Since the Lounge is, at present, AGONISINGLY slow (and the clock is 1 hr 18 mins slow!), it would take too long to post them. Since the files are also a bit lengthy, I will try tomorrow to send you a Private Message with them in, otherwise, if it’s STILL slow, could you let me have an email address in a private message so that I can send them in ZIPped form on Monday. That would also get over the % d a problem we have…

          • #763351

            John:
            I looked at the site, but it was too complex for me. I would very much appreciate it if you could combine it into the batch file that you wrote for me originally as it worked so well for me. Welcome back and Thanks.
            Jerome
            @echo off

            setlocal

            :: get today’s DoW, assuming US settings “DoW mm/dd/yyyy”
            for /f “tokens=1” %%a in (‘date /t’) do set DoW=%%a
            ECHO Day-of-the-Week from DATE /T is %DoW% & PAUSE

            :: tedious way of getting the full Day (more elegant ways are possible!)
            if “%DoW%”==”Mon” set day=Monday
            if “%DoW%”==”Tue” set day=Tuesday
            if “%DoW%”==”Wed” set day=Wednesday
            if “%DoW%”==”Thu” set day=Thursday
            if “%DoW%”==”Fri” set day=Friday
            if “%DoW%”==”Sat” set day=Saturday
            if “%DoW%”==”Sun” set day=Sunday
            ECHO Today’s (full name) day is

        • #763339

          Jerome

          Heck, why should I redo the work since Ritchie Lawrence has already done it all? grin (Go through “Batch Function Library” to “Date and Time Functions” to “DateToDoW”)

          If you have any trouble with the three functions he’s calling, just let me know and I’ll combine them into a single chunk of BATch code for you.

      • #763282

        John:
        I have been using this with great success till I upgraded to office 2003 which somehow affected windows XP. NOW I no longer get the day of the week. If I switch the regional settings to dddd, mm/dd/yyyy the batch works but it louse up microsoft money.
        Is there a way of drawing the day of the week from say the long date format of windows to get the day of the week, or do you have a newer solution??
        Thanks
        Jerome

    • #681470

      And Tim, don’t miss an opportunity to recruit another Lounger to AutoIt. Even though I’m still a novice with AutoIt, there are “special variables” built-in to the software, such as ” A_WDAY ” and a host of others.

      • #681478

        (Edited by TimOz on 01-Jun-03 20:05. Added PS)

        laugh I was tempted! And if John’s approach with the date command brings no joy, then AutoIt is a good canditate to help orchestrate the show. (On my sys it’s just dd-mm-yyyy, so I assumed it was the same elsewhere.)

        PS Looks like we missed the boat. Guess we could argue that it would provide a more elegant solution. grin

    Viewing 2 reply threads
    Reply To: XCOPY batch file that takes its name from weekday (Windows XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: