• Getting batch files to run

    Author
    Topic
    #409143

    At work, I am getting a new computer and will go from Windows 98 to Windows 2000. I use a set of two batch files to keep my office computer synchronized with my home computer.

    About a year ago, work tried to upgrade my existing computer to Windows 2000 and I could not get these batch files to work so I got them to reload Windows 98. This time with the new computer that is not an option. Unfortunately, I do not recall the specific problem of why they would not work.

    I will show the batch files and briefly describe them and I hope someone can tell me what I need to do to modify them to work under Windows 2000.

    I run these batch files on three different computers, one at work and two at home, to keep all three synchronized. Word runs Windows 98 but I have both Windows 95 and ME running at home.

    The first batch file uses the command line program PKZIP to zip all the modified files on my D-drive partition to a file on the S-drive:

    =====================================================
    REM First, it builds a path since Windows ME skips
    REM the batch file that I specify as the startup
    REM batch file and that one sets the path

    PATH;
    PATH=C:WINDOWS
    PATH=%PATH%;C:WINDOWSCOMMAND
    PATH=%PATH%;D:UTILITY
    PATH=%PATH%;D:BAT
    PATH=%PATH%;D:BATZIP
    PATH=%PATH%;D:ZIP

    REM Since Firebird uses a different subdirectory for
    REM each installation and you cannot specify a new
    REM location, I have to have the batch file look for
    REM the location on each machine and respond accordingly

    ECHO Copying Bookmarks to D-Drive
    IF EXIST C:WINDOWSApplic~1MozillaProfilesdefault1hvmp4ry.sltbookmarks.html XCOPY C:WINDOWSApplic~1MozillaProfilesdefault1hvmp4ry.sltbookmarks.html D:Bookmarks*.* /M
    IF EXIST C:WINDOWSApplic~1MozillaProfilesdefault0ix988m3.sltbookmarks.html XCOPY C:WINDOWSApplic~1MozillaProfilesdefault0ix988m3.sltbookmarks.html D:Bookmarks*.* /M
    IF EXIST C:WINDOWSApplic~1MozillaProfilesdefaulty4mlyg6k.sltbookmarks.html XCOPY C:WINDOWSApplic~1MozillaProfilesdefaulty4mlyg6k.sltbookmarks.html D:Bookmarks*.* /M

    REM I only keep data on my D-drive but there are some files I tell PKZIP
    REM to skip, mainly for housekeeping reasons

    PKZIP -ADD=Incremental -LEVEL=9 -DIR=ROOT S:D-DRIVE D:*.* -EXCLUDE=*.TMP -EXCLUDE=JUNK*.* -EXCLUDE=*.BAK -EXCLUDE=D:RECYCLED*.* -EXCLUDE=D:IMAGE.DAT -EXCLUDE=D:EUDORAATTACH*.* -EXCLUDE=D:_RESTORE*.*
    =====================================================

    The next batch file copies the changed files from the ZIP file on the S-drive onto the D-drive of the target computer. That is, I run the first batch file at work to archive the files to the S-drive then run this batch file at home to retrieve the changed files. In the morning, I repeat the process.

    =====================================================
    REM In order to handle deleting or renaming files
    REM without my having to remember, I just create a
    REM batch file on the S-drive called DOTHIS.BAT. This
    REM batch file checks for it and runs it if it finds it.

    REM Run DOTHIS.BAT if it exists
    REM ===========================
    IF EXIST S:DOTHIS.BAT CALL S:DOTHIS.BAT

    REM Unzip the files
    REM ===============
    D:
    CD
    IF EXIST S:D-DRIVE.ZIP D:ZIPPKZIP S:D-Drive -EXTRACT=Update -DIR=ROOT

    REM Copy Bookmarks
    REM ==============
    IF EXIST C:WINDOWSApplic~1MozillaProfilesdefault1hvmp4ry.slt*.html XCOPY D:BookmarksBookmarks.html C:WINDOWSApplic~1MozillaProfilesdefault1hvmp4ry.slt /M
    IF EXIST C:WINDOWSApplic~1MozillaProfilesdefault0ix988m3.slt*.html XCOPY D:BookmarksBookmarks.html C:WINDOWSApplic~1MozillaProfilesdefault0ix988m3.slt /M
    IF EXIST C:WINDOWSApplic~1MozillaProfilesdefaulty4mlyg6k.slt*.html XCOPY D:BookmarksBookmarks.html C:WINDOWSApplic~1MozillaProfilesdefaulty4mlyg6k.slt /M

    REM I cannot reset the entire drive at once after copying
    REM because I have Norton running and it generates an error
    REM if I try to reset its hidden subdirectory so I must process
    REM the subdirectories one-at-a-time

    REM Reset the archive bits if requested
    REM ===================================
    ECHO Resetting Archive Bits, This May Take A Few Moments

    ATTRIB -A D:ACCESS*.* /S
    ATTRIB -A D:ARC*.* /S
    ATTRIB -A D:BAT*.* /S
    ATTRIB -A D:BOOKMARKS*.* /S
    ATTRIB -A D:BOOKS*.* /S
    ATTRIB -A D:CICINDA*.* /S
    ATTRIB -A D:COMMON*.* /S
    ATTRIB -A D:DISCARD*.* /S
    ATTRIB -A D:DICTIONARY*.* /S
    ATTRIB -A D:ECONOM~1*.* /S
    ATTRIB -A D:EUDORA*.* /S
    ATTRIB -A D:HOMEPAGE*.* /S
    ATTRIB -A D:LETTERS*.* /S
    ATTRIB -A D:MONEY*.* /S
    ATTRIB -A D:MP3*.* /S
    ATTRIB -A D:NOTES*.* /S
    ATTRIB -A D:PERSONAL*.* /S
    ATTRIB -A D:RESEARCH*.* /S
    ATTRIB -A D:TEACHING*.* /S
    ATTRIB -A D:TEMPLATES*.*/S
    ATTRIB -A D:UTILITY*.* /S
    ATTRIB -A D:ZIP*.* /S

    =====================================================

    The batch files have more housekeeping chores, such as deleting an archive file after it has been used but these are the main commands. Any hints are appreciated.

    Ronny

    Viewing 7 reply threads
    Author
    Replies
    • #869831

      For starters if this will be a default install of Win2k it will be to C:winnt. I believe the variable for the windows installation directory is
      %windir%. That ought to help. For anything else perhaps the esteemed John Gray can be of assistance.

      Joe

      --Joe

    • #869832

      For starters if this will be a default install of Win2k it will be to C:winnt. I believe the variable for the windows installation directory is
      %windir%. That ought to help. For anything else perhaps the esteemed John Gray can be of assistance.

      Joe

      --Joe

    • #870373

      One of my favorite methods for debugging batch files was to add a variable called

    • #870374

      One of my favorite methods for debugging batch files was to add a variable called

    • #871509

      Ronny

      I really don’t know where to start, since there have been two major improvements to BATch file processing since Windows 98, and it would be good if your files could be rewritten to take advantage of them! They are unnecessarily lengthy, and could be made more general.

      You may be able to bypass some of the work by looking at the facilities offered by ROBOCOPY (definitely the XP/2003 version), XXCOPY or Karen’s Replicator (all Google-able) to “mirror” the contents of a directory tree of one computer onto another, and then vice-versa. There is a fairly steep learning curve in understanding what they do and how they work, but I found the first two invaluable for satisfying other and future requirements. I never got into the final one, although others swear by it!

      Can you say roughly how many files get copied and what the total size is? Why do you need to specify all those directories in the PATH? What is being used in each?

      If I get some time tomorrow I may look at doing a conversion “as is” to something that ought to run on Windows 2000.

      John

      PS It looks to me as if you have renamed the PKZIP v2.50 executable PKZIP25.EXE to be PKZIP.EXE – is this correct?

      • #871817

        Ronny

        I’ve had a stab at changing the files a bit – see the text attachment. Your original message appears with comment characters :: in columsn 1 and 2, as do my own comments. I tend to write everything in lowercase, which should make it clear what I’ve added.

        If you want to test any of it out, stick a PAUSE after each “chunk”.

        I’m not happy that you have to specify the subdirecory names , as in “xxxxxxxx.slt” – it would be possible to determine dynamically what these are from a DIR command, but I’ll leave this for the moment!

        John

        • #872091

          I am not able to redo the batch files to take advantage of anything specific to Windows 2000. I use them to keep several machines in sync and only one is running Windows 2000. The others are running Windows 95 (yea, I know) and Windows ME. Your guess was right, I did rename PKZIP25.EXE to PKZIP. I forgot I had done that until you mentioned it.

          I did some troubleshooting last night once IT got the machine up and running and I figured out that the batch files as is have two problems, one I can easily fix without breaking the batch files on the other machines and the other I could also fix but it would be very clunky and I figure there is a better way.

          First, the batch files set the path but Win 2000 ignores the path it sets. The only reason the batch files need the path is to run a couple of utilities and these are always in the D:UTILITY subdirectory on all computers so I can modify those lines of the batch file to specify the full path to the utilities. I should not have to do this but it does work.

          Second, the batch file does not run any command involving files or subdirectories with names longer than eight characters. That is, both of these fail:

          CALL MyBatchFile
          ATTRIB -a D:MySubdirectory

          while both of the following work just fine:

          CALL Batch
          ATTRIB -A Sub

          Now, if I rewrite the first commands to

          CALL MyBatc~1
          ATTRIB -a D:MySubd~1

          They also work but I worry that renaming files or adding files my change MyBatc~1.BAT to MyBatc~2.BAT and break the batch files. Plus, it looks clunky and Windows 2000 should be smart enough to handle long file names by now.

          BTW: The way I run these batch files is from the START menu. I created the start menu entries by just copying the menu files from the Windows 98 machine that I was swapping out. Since Windows 2000 behaves differently if you start a DOS session with COMMAND or CMD, I wonder if the way I am starting these batch files might somehow be related to the file name problems.

          BTW2: I have to specify the subdirectory names because of Norton. On all my systems, I have two hard drives, the C-drive for just problems and the D-drive for all my data. This way, it is easy for me to keep the data on all the computers in sync. Basically, I have a batch file that I run at the end of a session that looks for +A archive bits and zips all those files from the D-drive to a Zip disc. Pkzip will automatically reset the archive bit so it does not have to do anything else. On each target computer, I run another batch file that unzips the file from the Zip disc to that D-drive. Since Pkzip will not reset the archive bit this direction, the batch file has to do it. Before a recent release of Norton (I forget which one) I could just use the command

          ATTRIB -A D: /S

          but Norton creates a D:RECYCLED hidden subdirectory and I get a file sharring error with the above command so I have to cycle through every subdirectory on the D-drive individually, being sure to skip the D:RECYCLED one. What a pain. This batch file also renames the archive zip file when it has unloaded the files; otherwise, it would continue to grow and grow.

          That is the basic flow. It is a little more complicated than that because I keep nine older versions of the zip file (.BA1, .BA2,…) and because each of the three machines gets an archive file of its own so that I do not have to keep it straight in my head which one I have sync’ed yet and which one is waiting.

          Ronny

          • #872235

            Try enclosing the long filenames in quotes, e.g. CALL “MyBatchFile”.

            • #873234

              I did that and it works now. Thanks.

              Ronny

            • #873235

              I did that and it works now. Thanks.

              Ronny

          • #872236

            Try enclosing the long filenames in quotes, e.g. CALL “MyBatchFile”.

          • #872547

            If you’re saying that you can’t change the BATch file to include the improvements found in Windows 2000 there’s not much scope for alteration!

            Calvin has already pointed out that “file names with spaces” and “filenameslongerthan8characters” should be put in double quotes.

            I have no idea why your PATH statement doesn’t work in Windows 2000 – other than that you would need to change the WINDOWS-related directories to WINNT-related equivalents, which I included in my text file.

            Perhaps you need to check which operating system (to be more precise, which level of the Command Processor) you’re running on, so you could use commands specific to Windows 2000 when you’re running on Windows 2000? Probably the simplest method in your circumstance is to check whether you have an environment variable OS. In Windows 98 it is not present, in Windows NT 4 / 2000 / XP / etc it has the value Windows_NT. So you could incorporate code like
            IF “%OS%”==”” GOTO WINDOWS98
            :: code specific to Windows 2000 here
            SET PATH=C:WINNTSystem32;C:WINNT;C:WINNTSystem32Wbem;
            GOTO COMMON
            :WINDOWS98
            :: code specific to Windows 98 here (from memory!!)
            SET PATH=C:Windows;C:WindowsCommands;
            :COMMON
            SET PATH=%PATH%;all the other directories on your list

            John

          • #872548

            If you’re saying that you can’t change the BATch file to include the improvements found in Windows 2000 there’s not much scope for alteration!

            Calvin has already pointed out that “file names with spaces” and “filenameslongerthan8characters” should be put in double quotes.

            I have no idea why your PATH statement doesn’t work in Windows 2000 – other than that you would need to change the WINDOWS-related directories to WINNT-related equivalents, which I included in my text file.

            Perhaps you need to check which operating system (to be more precise, which level of the Command Processor) you’re running on, so you could use commands specific to Windows 2000 when you’re running on Windows 2000? Probably the simplest method in your circumstance is to check whether you have an environment variable OS. In Windows 98 it is not present, in Windows NT 4 / 2000 / XP / etc it has the value Windows_NT. So you could incorporate code like
            IF “%OS%”==”” GOTO WINDOWS98
            :: code specific to Windows 2000 here
            SET PATH=C:WINNTSystem32;C:WINNT;C:WINNTSystem32Wbem;
            GOTO COMMON
            :WINDOWS98
            :: code specific to Windows 98 here (from memory!!)
            SET PATH=C:Windows;C:WindowsCommands;
            :COMMON
            SET PATH=%PATH%;all the other directories on your list

            John

        • #872092

          I am not able to redo the batch files to take advantage of anything specific to Windows 2000. I use them to keep several machines in sync and only one is running Windows 2000. The others are running Windows 95 (yea, I know) and Windows ME. Your guess was right, I did rename PKZIP25.EXE to PKZIP. I forgot I had done that until you mentioned it.

          I did some troubleshooting last night once IT got the machine up and running and I figured out that the batch files as is have two problems, one I can easily fix without breaking the batch files on the other machines and the other I could also fix but it would be very clunky and I figure there is a better way.

          First, the batch files set the path but Win 2000 ignores the path it sets. The only reason the batch files need the path is to run a couple of utilities and these are always in the D:UTILITY subdirectory on all computers so I can modify those lines of the batch file to specify the full path to the utilities. I should not have to do this but it does work.

          Second, the batch file does not run any command involving files or subdirectories with names longer than eight characters. That is, both of these fail:

          CALL MyBatchFile
          ATTRIB -a D:MySubdirectory

          while both of the following work just fine:

          CALL Batch
          ATTRIB -A Sub

          Now, if I rewrite the first commands to

          CALL MyBatc~1
          ATTRIB -a D:MySubd~1

          They also work but I worry that renaming files or adding files my change MyBatc~1.BAT to MyBatc~2.BAT and break the batch files. Plus, it looks clunky and Windows 2000 should be smart enough to handle long file names by now.

          BTW: The way I run these batch files is from the START menu. I created the start menu entries by just copying the menu files from the Windows 98 machine that I was swapping out. Since Windows 2000 behaves differently if you start a DOS session with COMMAND or CMD, I wonder if the way I am starting these batch files might somehow be related to the file name problems.

          BTW2: I have to specify the subdirectory names because of Norton. On all my systems, I have two hard drives, the C-drive for just problems and the D-drive for all my data. This way, it is easy for me to keep the data on all the computers in sync. Basically, I have a batch file that I run at the end of a session that looks for +A archive bits and zips all those files from the D-drive to a Zip disc. Pkzip will automatically reset the archive bit so it does not have to do anything else. On each target computer, I run another batch file that unzips the file from the Zip disc to that D-drive. Since Pkzip will not reset the archive bit this direction, the batch file has to do it. Before a recent release of Norton (I forget which one) I could just use the command

          ATTRIB -A D: /S

          but Norton creates a D:RECYCLED hidden subdirectory and I get a file sharring error with the above command so I have to cycle through every subdirectory on the D-drive individually, being sure to skip the D:RECYCLED one. What a pain. This batch file also renames the archive zip file when it has unloaded the files; otherwise, it would continue to grow and grow.

          That is the basic flow. It is a little more complicated than that because I keep nine older versions of the zip file (.BA1, .BA2,…) and because each of the three machines gets an archive file of its own so that I do not have to keep it straight in my head which one I have sync’ed yet and which one is waiting.

          Ronny

      • #871818

        Ronny

        I’ve had a stab at changing the files a bit – see the text attachment. Your original message appears with comment characters :: in columsn 1 and 2, as do my own comments. I tend to write everything in lowercase, which should make it clear what I’ve added.

        If you want to test any of it out, stick a PAUSE after each “chunk”.

        I’m not happy that you have to specify the subdirecory names , as in “xxxxxxxx.slt” – it would be possible to determine dynamically what these are from a DIR command, but I’ll leave this for the moment!

        John

    • #871510

      Ronny

      I really don’t know where to start, since there have been two major improvements to BATch file processing since Windows 98, and it would be good if your files could be rewritten to take advantage of them! They are unnecessarily lengthy, and could be made more general.

      You may be able to bypass some of the work by looking at the facilities offered by ROBOCOPY (definitely the XP/2003 version), XXCOPY or Karen’s Replicator (all Google-able) to “mirror” the contents of a directory tree of one computer onto another, and then vice-versa. There is a fairly steep learning curve in understanding what they do and how they work, but I found the first two invaluable for satisfying other and future requirements. I never got into the final one, although others swear by it!

      Can you say roughly how many files get copied and what the total size is? Why do you need to specify all those directories in the PATH? What is being used in each?

      If I get some time tomorrow I may look at doing a conversion “as is” to something that ought to run on Windows 2000.

      John

      PS It looks to me as if you have renamed the PKZIP v2.50 executable PKZIP25.EXE to be PKZIP.EXE – is this correct?

    • #873236

      I appreciate all the help guys. I know everyone wanted me to completely rewrite them to take advantage of Windows 2000 specific stuff and I could have done that by using different batch files at home and at work but I prefer to just have to update one set. Making the changes suggested in this forum and a few I figured out myself, I think I have everything running now. The changes I had to make include:

      1. Specifying full path to programs since Windows 2000 seems to ignore path statements, or at least the way I was building the path statement
      2. Putting file names with more than eight characters in quotes even when there were no spaces or other illegal characters in the name.
      3. Dramatically editing PKZIP command line. Windows 2000 seems to only accept 128 character command lines while Windows 98 takes 256

      All of these changes indicate to me that Windows 2000 is less “user friendly” than Windows 98. I guess that goes along with being aimed at the corporate market rather than home users.

      Thanks again for all the help.

      Ronny

    • #873237

      I appreciate all the help guys. I know everyone wanted me to completely rewrite them to take advantage of Windows 2000 specific stuff and I could have done that by using different batch files at home and at work but I prefer to just have to update one set. Making the changes suggested in this forum and a few I figured out myself, I think I have everything running now. The changes I had to make include:

      1. Specifying full path to programs since Windows 2000 seems to ignore path statements, or at least the way I was building the path statement
      2. Putting file names with more than eight characters in quotes even when there were no spaces or other illegal characters in the name.
      3. Dramatically editing PKZIP command line. Windows 2000 seems to only accept 128 character command lines while Windows 98 takes 256

      All of these changes indicate to me that Windows 2000 is less “user friendly” than Windows 98. I guess that goes along with being aimed at the corporate market rather than home users.

      Thanks again for all the help.

      Ronny

    Viewing 7 reply threads
    Reply To: Getting batch files to run

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

    Your information: