Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: copying two text files using at command  (Read 13818 times)

0 Members and 1 Guest are viewing this topic.

pkranthi

    Topic Starter


    Rookie

    copying two text files using at command
    « on: February 04, 2008, 05:53:27 PM »
    Hi All,

    I am very new to msdos programming. My requirement looks simple but I could not do it. I have to schedule a copy of tow text files every week as they are generated. Actually now I am trying to do this with two sample text files but could not do it.

    The commands I am using are.

    at 7:50pm copy a1.txt +a2.txt a1.txt

    When I did that ti says error and when I went to the scheduler and saw the log it said some thing like this.

    Unable to start task.
       The specific error is:
       0x80070002: The system cannot find the file specified.

    When I do the copy with out the at command it works properly that is just this command.

    copy a1.txt +a2.txt a1.txt

    Please help me with this. I tried to put the same command in a batch file and tried to execute it, even then it give the same message.

    Thanks,
    kranthi

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: copying two text files using at command
    « Reply #1 on: February 05, 2008, 04:44:17 AM »
    The copy command runs in a window where the default directory may not be where the files are located. Best to use fully qualified file names.

    at 7:50pm copy a1.txt +a2.txt a1.txt

    Unless that's a typo, you're trying to overwrite one of the inputs with the output file.

     8)

    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    pkranthi

      Topic Starter


      Rookie

      Re: copying two text files using at command
      « Reply #2 on: February 05, 2008, 06:14:44 AM »
      Best to use fully qualified file names.

      What does fully qualified file names mean. The files are on my desktop and in the command prompt I am writing the       at 7:50pm copy a1.txt +a2.txt a1.txt in the same desktop directory(c:\documents and settings\....\desktop). Does fully qualified names mean the full path of the file? Please let me know, if this is not the right way to do it is there any other way to do it.

      at 7:50pm copy a1.txt +a2.txt a1.txt
      Unless that's a typo, you're trying to overwrite one of the inputs with the output file.

      No I am not trying to overwrite any file, I am copying the contents of a2 into a1.

      Thanks,
      kranthi

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: copying two text files using at command
      « Reply #3 on: February 05, 2008, 07:33:21 AM »
      Yes. The fully qualified name of a file is the full path including the drive.

      Quote
      The files are on my desktop and in the command prompt I am writing the       at 7:50pm copy a1.txt +a2.txt a1.txt in the same desktop directory(c:\documents and settings\....\desktop)

      That may be true, but what is the command window default directory when the scheduler opens it? On many machines, unless it's been changed, the default is the expansion of %homedrive%%homepath%. This is usually the user profile directory but it does not drill down to the desktop.

      The fact that you're getting a 0x80070002: The system cannot find the file specified message indicates the path or lack of one is the problem.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      pkranthi

        Topic Starter


        Rookie

        Re: copying two text files using at command
        « Reply #4 on: February 05, 2008, 08:16:47 AM »
        Ok got it now how to I change my present command line to make it work?

        ----what is the command window default directory when the scheduler opens it?

        How can I know what is the default directory. When I type the CMD at Run The command prompt opens as C:\Documents and Settings\u08432 and then I do CD Desktop to go to desktoop and I am writing the at command over there. (C:\Documents and Settings\u08432\desktop).

        ----On many machines, unless it's been changed, the default is the expansion of %homedrive%%homepath%.

        I did not understand what %homedrive%%homepath% this mean.

        Thanks for the reply.
        kranthi

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: copying two text files using at command
        « Reply #5 on: February 05, 2008, 08:51:07 AM »
        Quote
        C:\Documents and Settings\u08432 and then I do CD Desktop

        Exactly, but the scheduler is not going to do the CD Desktop and the copy command will not either. Rather it looks in the default (C:\Documents and Settings\u08432), doesn't find the files and throws the error.

        A couple of ways to fix this:

        Code: [Select]
        at 7:50pm copy desktop\a1.txt +desktop\a2.txt desktop\a1.txt

        That should work because the files live just one directory level below the default directory.

        To make it completely fool proof, give the processor the entire path to the file:

        Code: [Select]
        at 7:50pm copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt"


        When the command line gets this crazy, it might be easier to create and schedule a batch file. 8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        pkranthi

          Topic Starter


          Rookie

          Re: copying two text files using at command
          « Reply #6 on: February 05, 2008, 09:11:12 AM »
          -----at 7:50pm copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt"

          This did not work it threw the same error as before. I wrote the above command line at the following path C:\Documents and Settings\u08432>.


          -----at 7:50pm copy desktop\a1.txt +desktop\a2.txt desktop\a1.txt

          This did not work either and returns the same error.

          I tried to change the path where I write the command insted of C:\Documents and Settings\u08432> this I also tried it at C:\Documents and Settings\u08432\desktop>.
          Even then it gives the same error.

          In the microsoft site it said some thing like this but I could not understand it exactly.

          *****The at command does not automatically load cmd (the command interpreter) before it runs commands. Unless you are running an .exe file, you must load Cmd.exe at the beginning of the command, for example, at cmd /c dir > c:\test.txt. *****

          ------When the command line gets this crazy, it might be easier to create and schedule a batch file.

          How can I do this, I will try it may be that will work.

          Thanks,
          kranthi



          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: copying two text files using at command
          « Reply #7 on: February 05, 2008, 10:05:06 AM »
          Quote
          *****The at command does not automatically load cmd (the command interpreter) before it runs commands. Unless you are running an .exe file, you must load Cmd.exe at the beginning of the command, for example, at cmd /c dir > c:\test.txt. *****

          That would be an important piece of information. Either make a batch file with the copy command and then schedule the batch file (my personal favorite)

          OR

          Code: [Select]
          at 7:50pm cmd /c copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt"

          Good luck.  8)


          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein

          pkranthi

            Topic Starter


            Rookie

            Re: copying two text files using at command
            « Reply #8 on: February 05, 2008, 11:56:46 AM »
            -----at 7:50pm cmd /c copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt"

            I tried this before but did not work and even now it did not work I copied and pasted the same code as it is. This time after that particular time is over I could not see the schedule at all to see if it has error or if it is ok. But when I saw the txt file there is no change.

            ------Either make a batch file with the copy command and then schedule the batch file (my personal favorite)

            How to make a batch file I know of doing edit sample.bat and then in the file write the code. So will it be the same code what I write out side.

            cmd /c copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt"

            If I have to create a batch file The file should be created from the same directory where the text files to be copied are there or I can do it from my home directory?

            Thanks,
            kranthi



            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: copying two text files using at command
            « Reply #9 on: February 05, 2008, 12:42:27 PM »
            The batch file:

            Code: [Select]
            copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt"

            You can put the batch file anywhere you want, but when you schedule the job, you must point to the batch file.

            Code: [Select]
            at 7:50pm path\batch.bat

            A batch file is a better choice here as the .bat or .cmd extension will force the cmd processor to run. The embedded spaces in the path only complicate things. After the scheduled time has elapsed, check the scheduler. The Status column should indicate what happened.

             8)

            PS. I apologize for getting the punctuation wrong on my last post.
            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            pkranthi

              Topic Starter


              Rookie

              Re: copying two text files using at command
              « Reply #10 on: February 05, 2008, 12:59:02 PM »
              -----copy "C:\Documents and Settings\u08432\desktop\a1.txt" +"C:\Documents and Settings\u08432\desktop\a2.txt" "C:\Documents and Settings\u08432\desktop\a1.txt.

              I have kept the above code in sample.bat and saved it to my dektop and execute the batch file with at as follows

              C:\Documents and Settings\u08432>at 2:53PM C:\Documents and Settings\u08432\desktop\sample.bat. No Progress

              at the task scheduler it says: Could not Start.

              and the log says this:

              "At1.job" (Documents) 2/5/2008 2:53:00 PM ** ERROR **
                 Unable to start task.
                 The specific error is:
                 0x80070002: The system cannot find the file specified.
                 Try using the Task page Browse button to locate the application.

              Thanks for all the replies
              kranthi

              pkranthi

                Topic Starter


                Rookie

                Re: copying two text files using at command
                « Reply #11 on: February 05, 2008, 01:35:33 PM »
                I tried everything in another direcotry c:\kranthi it worked and I figured it out that previously it did not work because of the spaces in the path Documents and Settings. This is fine but on the server where I have to perform this schedule it has spaces in the path and how to make it work even if there are spaces in the path.

                Thanks,
                kranthi

                pkranthi

                  Topic Starter


                  Rookie

                  Re: copying two text files using at command
                  « Reply #12 on: February 05, 2008, 01:50:43 PM »
                  GOT IT..... ;D.

                  irespective of the text filees I kept the bat file in the path where there are no spaces in the path and scheduled the bat file with the path. As the there are no spaces in the path where the bat file is the scheduler did not have any problem. Even the text files are at the path where there spaces in the path it is not a problem because we are putting the copy code in the batch file and in the batch file the path is inside the " ", it worked.

                  Now I have one more small doubt. I have check if a2 exists before doing the copy into a1 and if it does not exist the batch file should be execute after one hour and this should continue until it sees a2 and copies the content to a1. Is this possible?

                  Please let me know.

                  Thanks Sidewinder. Thanks a lot
                  kranthi

                  Sidewinder



                    Guru

                    Thanked: 139
                  • Experience: Familiar
                  • OS: Windows 10
                  Re: copying two text files using at command
                  « Reply #13 on: February 05, 2008, 02:12:26 PM »
                  Anything is possible and if you have access to the sleep command you could build a batch file without getting involved with the task scheduler.

                  Code: [Select]
                  @echo off
                  :loop
                  if exist a2.txt (
                                copy ...
                      ) else (
                                sleep 60
                               goto loop
                   )

                  Good luck.  8)

                  Note: building a loop without the sleep will suck up cpu cycles.

                  The true sign of intelligence is not knowledge but imagination.

                  -- Albert Einstein

                  pkranthi

                    Topic Starter


                    Rookie

                    Re: copying two text files using at command
                    « Reply #14 on: February 05, 2008, 04:16:17 PM »
                    Thanks for that but I need the schedule even because I have to check for a2 only on every monday but if by the time my schedule runs if there is no a2 then I have make my schedule check for every hour until it sees a2 and copies the content to a1.

                    Thanks,
                    kranthi.