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

Author Topic: New member, New DOS adventurer.  (Read 19560 times)

0 Members and 1 Guest are viewing this topic.

robertwig

    Topic Starter


    Rookie
  • The Dos and Don'ts of my new life
    • Experience: Beginner
    • OS: Windows 7
    New member, New DOS adventurer.
    « on: January 21, 2014, 05:27:58 PM »
    Good day folks;

    I'm new to this board and to DOS batch programming.
    I have been spending some time with DOS in hopes of gaining the ability to program some batch files for my home pc.
    I have had some success but could use some direction from those who have been at it for some time.

    I would appreciate knowing how to address the problem of "locating a specific directory across all the drives on my system and returning the path (drive:\directoryname) to a variable that I could pass on to other parts of my batch dos program.

    I have used the following to return most of what I need:

    dir /d MyOFFSetupFiles | findstr "\<Directory of\>"
    this returns the following string to the console:  Directory of C:\MyOFFSetupFiles

    What I need to do with this console output is strip of the "Directory of" portion and pass the "C:\MyOFFSetupFiles" on to a variable I can use further on in the batch run.

    I have looked at the FOR command, but the complexity is too big of a jump for me at my stage of programming. I just can't fathom how to implement it but I think it might be what I need. Is there a simple way to parse the portion I need into a variable?

    Any help would be appreciated. Thanks in advance for taking the time to look at this.

    Best Regards






    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: New member, New DOS adventurer.
    « Reply #1 on: January 21, 2014, 06:08:58 PM »
    Assuming I understood you correctly (I'm somewhat brain dead right now) but you want to set the output of ' dir /d MyOFFSetupFiles | findstr "\<Directory of\>" ' as the value of a variable.

    You were correct in your assumption that you need a For loop.  I'll post the code below and walk you through how it works.

    Assuming your command gives the output: "Directory of C:\MyOFFSetupFiles" without the quotes.
    Code: [Select]
    :: So first we must enable delayed expansion, so we can change and use the value of variables inside the for loop.
    setlocal EnableDelayedExpansion

    :: Now we start the first for loop.  This one will seperate the output of the command into two parts based on the possition of (:).
    :: This will allow us to isolate the path, (which will be stored as %%B for the duration of the loop.
    for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\<Directory of\>"') do (

    :: Now to deal with the fact that the drive is in the other segment, we must seperate that segment of output further until we only
    :: have the drive letter.  To do this we use another for loop.  This time we seperate the string %%A (the first half of the original output)
    :: based on the possition of spaces, only holding onto the first three segments. They will be stored in %%G, %%H, %%I respectively.
    :: Now since the drive letter is found singularly in the 3rd segment, we move that into a variable until we can join it up with our
    :: path (stored in %%B)
    for /f "tokens=1-3 delims= " %%G in ("%%A") do (
    set "findPath_drv=%%I:"
    )

    :: To complete the operation, we combine the two variables into a single one, and empty our temporary variable used to store
    :: the drive letter
    set findPath=!findPath_drv!%%B
    set findPath_drv=
    )

    :: This is simply to allow us to test to see if the operation was completed successfully.
    echo %findpath%
    pause

    This is possible to do without using 'setlocal EnableDelayedExpansion' via this code:
    Code: [Select]
    for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\<Directory of\>"') do (
    for /f "tokens=1-3 delims= " %%G in ("%%A") do (
    set "findPath=%%I:%%B"
    )
    )
    echo %findpath%
    pause
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    robertwig

      Topic Starter


      Rookie
    • The Dos and Don'ts of my new life
      • Experience: Beginner
      • OS: Windows 7
      Re: New member, New DOS adventurer.
      « Reply #2 on: January 21, 2014, 06:37:17 PM »
      Lemonilla;

      It's amazing that once you see an example it seems so clear. I am finding that with most of my exposure to DOS, the command are mind boggling until you see some examples. Could I hit on you for a recommendation of reading material that in your opinion really has some extensive examples that make use of the majority of the features of most commands and also shows how to link them via piping, FOR, and other methods.

      Just looking at the dos commands fields only gets me in the door and frustrates me trying to determine how to mix and match them.
      Very basic stuff comes easy but the more complex mix requires me to understand far more than I can get without a proper guide.

      I am very thankful for what you have provided to me and your description was extremely helpful.

      Thanks again and any suggested reading material would be grateful either  by PM or here.

      Best Regards;

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: New member, New DOS adventurer.
      « Reply #3 on: January 21, 2014, 07:01:32 PM »
      If you read the last section of the FOR /help.
      You might be surprised on how to do this a little simpler with the modifiers.

      Lemonilla



        Apprentice

      • "Too sweet"
      • Thanked: 70
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: New member, New DOS adventurer.
      « Reply #4 on: January 21, 2014, 07:20:48 PM »
      Lemonilla;

      It's amazing that once you see an example it seems so clear. I am finding that with most of my exposure to DOS, the command are mind boggling until you see some examples. Could I hit on you for a recommendation of reading material that in your opinion really has some extensive examples that make use of the majority of the features of most commands and also shows how to link them via piping, FOR, and other methods.

      Just looking at the dos commands fields only gets me in the door and frustrates me trying to determine how to mix and match them.
      Very basic stuff comes easy but the more complex mix requires me to understand far more than I can get without a proper guide.

      I am very thankful for what you have provided to me and your description was extremely helpful.

      Thanks again and any suggested reading material would be grateful either  by PM or here.

      Best Regards;

      I'd love to, but I don't really have much.  I learned all of my knowledge base from http://ss64.com/nt/ and from posting questions on the forum.  Mostly you just have to mess around and write a bunch of goofy stuff until you start to get the hang of it.

      If you read the last section of the FOR /help.
      You might be surprised on how to do this a little simpler with the modifiers.
      But that would require *gasp* reading!
      Noted, I'll look into it.



      On another note, I believe what you are looking for is %cd%, which passively holds the current directories path.
      Code: [Select]
      T:\lib>dir /d
       Volume in drive T is Testing
       Volume Serial Number is 6694-3ABE

       Directory of T:\lib

      [.]                 [Amy Tintera]       [Blake, Kendare]
      [..]                [Ari Harper]        [Tad Williams]
      $lib.bat            [Becca Fitzpatrick]
                     1 File(s)            836 bytes
                     7 Dir(s)   5,231,140,864 bytes free

      T:\lib>echo "%cd%"
      "T:\lib"
      ( I used quotes to help differentiate from the prompt [the default of which is "%cd%>" or $P$G in the 'prompt' command])
      « Last Edit: January 21, 2014, 07:38:39 PM by Lemonilla »
      Quote from: patio
      God Bless the DOS Helpers...
      Quote
      If it compiles, send the files.

      robertwig

        Topic Starter


        Rookie
      • The Dos and Don'ts of my new life
        • Experience: Beginner
        • OS: Windows 7
        Re: New member, New DOS adventurer.
        « Reply #5 on: January 21, 2014, 09:19:32 PM »
        Assuming I understood you correctly (I'm somewhat brain dead right now) but you want to set the output of ' dir /d MyOFFSetupFiles | findstr "\<Directory of\>" ' as the value of a variable.

        You were correct in your assumption that you need a For loop.  I'll post the code below and walk you through how it works.

        Assuming your command gives the output: "Directory of C:\MyOFFSetupFiles" without the quotes.
        Code: [Select]
        :: So first we must enable delayed expansion, so we can change and use the value of variables inside the for loop.
        setlocal EnableDelayedExpansion

        :: Now we start the first for loop.  This one will seperate the output of the command into two parts based on the possition of (:).
        :: This will allow us to isolate the path, (which will be stored as %%B for the duration of the loop.
        for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\<Directory of\>"') do (

        :: Now to deal with the fact that the drive is in the other segment, we must seperate that segment of output further until we only
        :: have the drive letter.  To do this we use another for loop.  This time we seperate the string %%A (the first half of the original output)
        :: based on the possition of spaces, only holding onto the first three segments. They will be stored in %%G, %%H, %%I respectively.
        :: Now since the drive letter is found singularly in the 3rd segment, we move that into a variable until we can join it up with our
        :: path (stored in %%B)
        for /f "tokens=1-3 delims= " %%G in ("%%A") do (
        set "findPath_drv=%%I:"
        )

        :: To complete the operation, we combine the two variables into a single one, and empty our temporary variable used to store
        :: the drive letter
        set findPath=!findPath_drv!%%B
        set findPath_drv=
        )

        :: This is simply to allow us to test to see if the operation was completed successfully.
        echo %findpath%
        pause

        This is possible to do without using 'setlocal EnableDelayedExpansion' via this code:
        Code: [Select]
        for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\<Directory of\>"') do (
        for /f "tokens=1-3 delims= " %%G in ("%%A") do (
        set "findPath=%%I:%%B"
        )
        )
        echo %findpath%
        pause

        Lemonilla;

        PLease ignore the following!! DUH!! I labelled my file with extension "txt" instead of "bat". I have got to get some sleep!! Sorry.
        Your c ode worked great. Now I have to build on it. Thanks again

        I tried your code but was surprised to get the response I did.  Any ideas of what I did wrong here? See below:

        Microsoft Windows [Version 6.0.6002]
        Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

        C:\>code: [select]
        'code:' is not recognized as an internal or external command,
        operable program or batch file.

        C:\>setlocal EnableDelayedExpansion

        C:\>for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\,D
        irectory of\>"') do (for /f "tokens=1-3 delims= " %%G in ("%%A") do (set "findpa
        th=%%I:%%B"))
        %%A was unexpected at this time.

        C:\>echo %findpath%
        %findpath%

        C:\>dir /d MyOFFSetupFiles ^| findstr "\,Directory of\>"
        The system cannot find the file specified.

        C:\>dir /d MyOFFSetupFiles | findstr "\
         Directory of C:\MyOFFSetupFiles

        C:\>setlocal EnableDelayedExpansion

        C:\>for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\<D
        irectory of\>"') do (
        %%A was unexpected at this time.

        C:\>for /f "tokens=1-3 delims= " %%G in ("%%A") do (set "findPath=%%I:%%B"))
        %%G was unexpected at this time.

        C:\>echo %findpath%
        %findpath%

        C:\>pause
        « Last Edit: January 21, 2014, 09:39:35 PM by robertwig »

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: New member, New DOS adventurer.
        « Reply #6 on: January 21, 2014, 09:28:09 PM »
        C:\>code: [select]
        Surely you didn't copy and paste that into your batch file.

        robertwig

          Topic Starter


          Rookie
        • The Dos and Don'ts of my new life
          • Experience: Beginner
          • OS: Windows 7
          Re: New member, New DOS adventurer.
          « Reply #7 on: January 21, 2014, 09:42:07 PM »
          Yes! DUH, and as I said to Lemonilla, I labelled my file extension as "TXT" instead of "BAT". Now that I have made a fool of myself I shall slink out the back door!!!

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: New member, New DOS adventurer.
          « Reply #8 on: January 21, 2014, 09:49:21 PM »
          This should check every drive for the foldername and return the very first match found.

          Code: [Select]
          @echo off
          del "folderlist.txt" 2>nul
          for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
             if exist %%a:\ dir "%%a:\foldername" /ad /b /s >>"folderlist.txt"
          )
          if not exist "folderlist.txt" echo no match found & goto :EOF
              set /p var=<"folderlist.txt"
              echo "%var%"

          robertwig

            Topic Starter


            Rookie
          • The Dos and Don'ts of my new life
            • Experience: Beginner
            • OS: Windows 7
            Re: New member, New DOS adventurer.
            « Reply #9 on: January 21, 2014, 11:13:47 PM »
            Foxidrive;

            I like your code but I really don't want to create a file on disk. I would rather pass the info on to a variable that I can use to position to the found top level directory for further processing. All I want to see in the variable is the high level DRIVELETTER:\DIRECTORYNAME
            I was unable to find any reference to your use of the phrase: >>"folderlist.txt" and would like to substitute a variable here but I'm not sure how to proceed.

            Hope you can clarify this for me.

            Thanks for your response it was appreciated.


            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: New member, New DOS adventurer.
            « Reply #10 on: January 21, 2014, 11:36:13 PM »
            Quote
            (c d e f g h i j k l m n o p q r s t u v w x y z)
            Does not include drive A and B. Was that intentional?  ::)

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: New member, New DOS adventurer.
            « Reply #11 on: January 21, 2014, 11:40:59 PM »
            Does not include drive A and B. Was that intentional?  ::)

            Yes, not many people use floppies and USB floppy drives, which are the main things you'd find on A: and B:


            Foxidrive;

            I like your code but I really don't want to create a file on disk.

            Why not?  It's called a temporary file.
            Are you aware that Windows itself could not run without creating temporary files?

            It's really funny to hear people say they don't want a temporary file, without a good reason for not being able to use one.

            Lemonilla



              Apprentice

            • "Too sweet"
            • Thanked: 70
            • Computer: Specs
            • Experience: Experienced
            • OS: Windows 7
            Re: New member, New DOS adventurer.
            « Reply #12 on: January 22, 2014, 05:18:41 AM »
            Foxidrive;

            I like your code but I really don't want to create a file on disk. I would rather pass the info on to a variable that I can use to position to the found top level directory for further processing. All I want to see in the variable is the high level DRIVELETTER:\DIRECTORYNAME
            I was unable to find any reference to your use of the phrase: >>"folderlist.txt" and would like to substitute a variable here but I'm not sure how to proceed.

            Hope you can clarify this for me.

            Thanks for your response it was appreciated.

            It is a redirection method.  ">> DESTINATION" means that it will add the output to destination, normally a temporary file, which can be used later. "> DESTINATION" replaces destination with a new file who's contense is the output of the command. There are also &,&&,|,||.

            Because of the limitations on dos variables, temporary files are sometimes necessary.  You just have to remember to remove them at the end.
            Quote from: patio
            God Bless the DOS Helpers...
            Quote
            If it compiles, send the files.

            Squashman



              Specialist
            • Thanked: 134
            • Experience: Experienced
            • OS: Other
            Re: New member, New DOS adventurer.
            « Reply #13 on: January 22, 2014, 06:18:08 AM »

            I was unable to find any reference to your use of the phrase: >>"folderlist.txt" and would like to substitute a variable here but I'm not sure how to proceed.
            The the first line of the temporary file is being put into the variables called VAR.  That is why you see the redirection in the SET /P command and the code then echos that variable to the screen to show you that it was set.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: New member, New DOS adventurer.
            « Reply #14 on: January 22, 2014, 06:24:59 AM »
            After my tantrum, I whipped this up.   

            Code: [Select]
            @echo off
            for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
                if exist %%a:\ for /f "delims=" %%b in ('dir "%%a:\foldername" /ad /b /s') do set "var=%%b" & goto :done
            )
            :done

            It's just very annoying when people ask for a solution and you provide one, and they didn't say SORRY, I CAN"T USE ANY TEMPORARY FILES in the first place.

            robertwig

              Topic Starter


              Rookie
            • The Dos and Don'ts of my new life
              • Experience: Beginner
              • OS: Windows 7
              Re: New member, New DOS adventurer.
              « Reply #15 on: January 22, 2014, 12:18:31 PM »
              After my tantrum, I whipped this up.   

              Code: [Select]
              @echo off
              for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
                  if exist %%a:\ for /f "delims=" %%b in ('dir "%%a:\foldername" /ad /b /s') do set "var=%%b" & goto :done
              )
              :done

              It's just very annoying when people ask for a solution and you provide one, and they didn't say SORRY, I CAN"T USE ANY TEMPORARY FILES in the first place.

              Foxidrive;

              I'm sorry if you got this impression. It was not a criticism or complaint in any way. I'm new to dos and learning here. The reason (which I did not elucidate on in my original request, is that I do not want to generate any files on the client machine. I want my code to be somewhat unobtrusive. I apologize if I ticked you off. I am learning quite a lot from this thread and I appreciate your time.

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: New member, New DOS adventurer.
              « Reply #16 on: January 22, 2014, 12:23:55 PM »
              But the temp file was just being redirected into a variable anyways.  You could have then just deleted the temp file.  It would have been on the system for all of 2 seconds.

              robertwig

                Topic Starter


                Rookie
              • The Dos and Don'ts of my new life
                • Experience: Beginner
                • OS: Windows 7
                Re: New member, New DOS adventurer.
                « Reply #17 on: January 22, 2014, 12:28:10 PM »
                But the temp file was just being redirected into a variable anyways.  You could have then just deleted the temp file.  It would have been on the system for all of 2 seconds.

                Your point is valid, and it may just be semantics but If my code failed for some reason it might be possible that the file did not get deleted. It may be a slim issue and as I said, I'm new to this but I didn't want to have the possibility of leaving any footprint so to speak.

                Lemonilla



                  Apprentice

                • "Too sweet"
                • Thanked: 70
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: New member, New DOS adventurer.
                « Reply #18 on: January 22, 2014, 12:59:20 PM »
                To fix the point you brought up, about having the program fail and leave behind a file, you can always add a point at the beginning to check to see if there is a temporary file, and if so delete it.  This would ensure that the next time you draw from the temporary file you don't get the wrong info. To do this you use a "modified" if statement.

                if exist temp.file del temp.file

                I like to add the /f switch to 'del' in case some other program decides it needs to read the file at that exact time (which has happened to me more times than I like to think about.)
                Quote from: patio
                God Bless the DOS Helpers...
                Quote
                If it compiles, send the files.

                Salmon Trout

                • Guest
                Re: New member, New DOS adventurer.
                « Reply #19 on: January 22, 2014, 01:40:24 PM »
                First post:

                Quote
                I have been spending some time with DOS in hopes of gaining the ability to program some batch files for my home pc.

                Later:

                Quote
                I do not want to generate any files on the client machine. I want my code to be somewhat unobtrusive

                Later still:

                Quote
                I didn't want to have the possibility of leaving any footprint

                Hmmm.... first it's "my home PC", then it's a "client machine" where you don't want someone (the owner?) to notice what you are doing? Sorry if this sounds supicious, but how do you explain the change of intended machine, and the reason you want the code to operate in an "unobtrusive" manner, and not leave "footprints"?



                robertwig

                  Topic Starter


                  Rookie
                • The Dos and Don'ts of my new life
                  • Experience: Beginner
                  • OS: Windows 7
                  Re: New member, New DOS adventurer.
                  « Reply #20 on: January 22, 2014, 02:52:10 PM »
                  First post:

                  Later:

                  Later still:

                  Hmmm.... first it's "my home PC", then it's a "client machine" where you don't want someone (the owner?) to notice what you are doing? Sorry if this sounds supicious, but how do you explain the change of intended machine, and the reason you want the code to operate in an "unobtrusive" manner, and not leave "footprints"?

                  It's going to be a tool for backup purposes which I and my family members pc's need. Therefore I want to make sure I do not alter the contents of their hard drives but the backups will ultimately go to a network drive we share in our home.
                  With the questions I'm asking which are very basic to skilled dos people I am far from capable of being subversive.

                  Squashman



                    Specialist
                  • Thanked: 134
                  • Experience: Experienced
                  • OS: Other
                  Re: New member, New DOS adventurer.
                  « Reply #21 on: January 22, 2014, 04:00:53 PM »
                  Leaving a 10 byte temp file is no big deal. Especially if you just use the Temp directory to write it to.  Nobody will even know it is there because most people dont even bother to clear out the temp folders. Windows and all kinds of programs dump files into temp folders every day you use your computer. Kind of maiking a mountain out of a mole hill.

                  patio

                  • Moderator


                  • Genius
                  • Maud' Dib
                  • Thanked: 1769
                    • Yes
                  • Experience: Beginner
                  • OS: Windows 7
                  Re: New member, New DOS adventurer.
                  « Reply #22 on: January 22, 2014, 04:27:34 PM »
                  It's going to be a tool for backup purposes which I and my family members pc's need. Therefore I want to make sure I do not alter the contents of their hard drives but the backups will ultimately go to a network drive we share in our home.
                  With the questions I'm asking which are very basic to skilled dos people I am far from capable of being subversive.

                  Unfortunately i'm with Salmon on this...if you are offended oh well.
                  " Anyone who goes to a psychiatrist should have his head examined. "

                  robertwig

                    Topic Starter


                    Rookie
                  • The Dos and Don'ts of my new life
                    • Experience: Beginner
                    • OS: Windows 7
                    Re: New member, New DOS adventurer.
                    « Reply #23 on: January 22, 2014, 08:56:10 PM »
                    Ok, I really don't want to argue over the use or not of temp files. It's just a matter of choice is it not? I take no offence in anyone's statements. I just prefer to not to use that approach.

                    This is the approach I am currently working on:

                     for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
                        if exist %%a:\ for /f "delims=" %%b in ('dir "%%a:\MyOFFSetupFiles" /ad /b /s') do set "var=%%b" & goto :done
                    )
                    :done

                    It works if the file exists, but if it doesn't the batch file just hangs there. I am having some difficulties with syntactically using the "else" to echo back that the file does not exist and to force an exit after the echo. I presume I could test var for null data as well and generate an appropriate echo message. Again I am having difficulty establishing where to fit in the Else appropriately.

                    Any assistance with this would be appreciated

                    Best Regards;


                    foxidrive



                      Specialist
                    • Thanked: 268
                    • Experience: Experienced
                    • OS: Windows 8
                    Re: New member, New DOS adventurer.
                    « Reply #24 on: January 22, 2014, 11:15:05 PM »
                    This is the approach I am currently working on:

                     for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
                        if exist %%a:\ for /f "delims=" %%b in ('dir "%%a:\MyOFFSetupFiles" /ad /b /s') do set "var=%%b" & goto :done
                    )
                    :done

                    It works if the file exists, but if it doesn't the batch file just hangs there.

                    Not at all.  If the folder doesn't exist then it will read every drive in every folder, and then when it doesn't find it, it will exit.

                    You probably have either several drives or a slow network drive and it was still checking.


                    robertwig

                      Topic Starter


                      Rookie
                    • The Dos and Don'ts of my new life
                      • Experience: Beginner
                      • OS: Windows 7
                      Re: New member, New DOS adventurer.
                      « Reply #25 on: January 23, 2014, 06:36:00 AM »
                      Not at all.  If the folder doesn't exist then it will read every drive in every folder, and then when it doesn't find it, it will exit.

                      You probably have either several drives or a slow network drive and it was still checking.

                      Thanks for the reply Foxidrive;

                      I only have a C: and an E: drive(CD Rom) in my system and the program just sits there without coming back with a cursor return when the folder does not exist. If the folder exists, everything works fine. I'm puzzled by this. I left it running for 5 minutes and it still did not return. Do you have any idea what might cause this

                      Squashman



                        Specialist
                      • Thanked: 134
                      • Experience: Experienced
                      • OS: Other
                      Re: New member, New DOS adventurer.
                      « Reply #26 on: January 23, 2014, 06:40:10 AM »
                      Is the /S option really needed?

                      robertwig

                        Topic Starter


                        Rookie
                      • The Dos and Don'ts of my new life
                        • Experience: Beginner
                        • OS: Windows 7
                        Re: New member, New DOS adventurer.
                        « Reply #27 on: January 23, 2014, 06:57:15 AM »
                        Is the /S option really needed?

                        I can do without it. Why do you ask?

                        Squashman



                          Specialist
                        • Thanked: 134
                        • Experience: Experienced
                        • OS: Other
                        Re: New member, New DOS adventurer.
                        « Reply #28 on: January 23, 2014, 07:09:26 AM »
                        I can do without it. Why do you ask?
                        If you can do without it then you should know what the /S option does and realize why it is taking so long to run when the folder does not exist.

                        robertwig

                          Topic Starter


                          Rookie
                        • The Dos and Don'ts of my new life
                          • Experience: Beginner
                          • OS: Windows 7
                          Re: New member, New DOS adventurer.
                          « Reply #29 on: January 23, 2014, 07:23:58 AM »
                          Yes I know it looks into recursive dir and files but I sure didn't think it would take so long. I will remove it and see what happens. Thanks for the tip.

                          robertwig

                            Topic Starter


                            Rookie
                          • The Dos and Don'ts of my new life
                            • Experience: Beginner
                            • OS: Windows 7
                            Re: New member, New DOS adventurer.
                            « Reply #30 on: January 23, 2014, 07:30:06 AM »
                            If you can do without it then you should know what the /S option does and realize why it is taking so long to run when the folder does not exist.

                            Wow, the removal of /s did allow completeion quickly. I thought I had a programming script error. I wonder how long it would have taken to complete with the /s still in. I waited 5 minutes and it was still running!

                            Your tip has made my day, thanks.

                            foxidrive



                              Specialist
                            • Thanked: 268
                            • Experience: Experienced
                            • OS: Windows 8
                            Re: New member, New DOS adventurer.
                            « Reply #31 on: January 23, 2014, 08:04:13 AM »
                            I didn't realise your folder was always in the root directory.   

                            That will certainly speed it up without the /s :)

                            It's funny that you now claim you only have a c: drive and cdrom, because in an earlier post you said

                            Quote
                            but the backups will ultimately go to a network drive we share in our home.

                            robertwig

                              Topic Starter


                              Rookie
                            • The Dos and Don'ts of my new life
                              • Experience: Beginner
                              • OS: Windows 7
                              Re: New member, New DOS adventurer.
                              « Reply #32 on: January 23, 2014, 12:49:44 PM »
                              I didn't realise your folder was always in the root directory.   

                              That will certainly speed it up without the /s :)

                              It's funny that you now claim you only have a c: drive and cdrom, because in an earlier post you said

                              I'm just testing in my bare bones environment on a notebook. the util will run on my desktop in a shared environment with my family.

                              robertwig

                                Topic Starter


                                Rookie
                              • The Dos and Don'ts of my new life
                                • Experience: Beginner
                                • OS: Windows 7
                                Re: New member, New DOS adventurer.
                                « Reply #33 on: January 23, 2014, 01:27:56 PM »
                                It seems I am not quite there yet.
                                The following code returns the data I wish to use (drive letter and folder name) but does not loop through all the drives on my system:

                                cd \
                                echo
                                for /f "tokens=1,2 delims=:" %%A in ('dir /d MyOFFSetupFiles ^| findstr "\<Directory of\>"') do (
                                for /f "tokens=1-3 delims= " %%G in ("%%A") do (set "findPath=%%I:%%B" & set drvltr=%%I) )
                                echo drive is %drvltr%
                                echo folder path is %findpath%
                                pause

                                This routine does a loops through all the drives but without the /S option on the DIR cmd I don't capture the data I need (drive letter and folder name). With the /s option, it takes too long if the condition is non existant.

                                cd \
                                rem echo off
                                for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (if exist %%a:\ for /f "delims=" %%b in ('dir "%%a:\MyOFFSetupFiles" /ad /b /s') do set "var=%%b" & goto :folderfound)
                                @echo Folder MyOFFSetupFiles does not exist
                                @echo program terminating
                                timeout 4
                                exit
                                :folderfound
                                echo %var%
                                for /f "tokens=1,2 delims=\" %%i in ("%var%") do set "drvltr=%%i" & set "folder=%%j"
                                set "path=%drvltr%\%folder%\
                                @echo drive is: %drvltr%
                                @echo folder is: %folder%
                                @echo path is: %path%
                                pause
                                exit

                                I have been trying to take the code that loops through the drives and build it into the first program but again I am having issues with the logic. Is there a way to merge the best of the two programs?

                                Raven19528



                                  Hopeful
                                • Thanked: 30
                                  • Computer: Specs
                                  • Experience: Experienced
                                  • OS: Windows 7
                                  Re: New member, New DOS adventurer.
                                  « Reply #34 on: January 23, 2014, 04:00:48 PM »
                                  I would suggest taking a look at Squashman's original suggestion.
                                  If you read the last section of the FOR /help.
                                  You might be surprised on how to do this a little simpler with the modifiers.
                                  If you work on your first block of code with those modifiers, you should be able to extract what you want very easily.

                                  Give it a shot and post back if you get stuck.
                                  "All things that are
                                  Are with more spirit chased than enjoy'd" -Shakespeare

                                  robertwig

                                    Topic Starter


                                    Rookie
                                  • The Dos and Don'ts of my new life
                                    • Experience: Beginner
                                    • OS: Windows 7
                                    Re: New member, New DOS adventurer.
                                    « Reply #35 on: January 23, 2014, 04:42:17 PM »
                                    I would suggest taking a look at Squashman's original suggestion. If you work on your first block of code with those modifiers, you should be able to extract what you want very easily.

                                    Give it a shot and post back if you get stuck.

                                    I looked at the for help on modifiers, but I don't see how they will help me with the ability  to Loop through all the potential drives like I have in the second block of code I posted. I must be missing something about your suggestion.

                                    Squashman



                                      Specialist
                                    • Thanked: 134
                                    • Experience: Experienced
                                    • OS: Other
                                    Re: New member, New DOS adventurer.
                                    « Reply #36 on: January 23, 2014, 07:37:55 PM »
                                    If this is a program that you are going to use on your family's computers and network to do some kind of backup why are we screwing around with trying to search and destroy for your program on every drive letter that might be connected to the system?  It is almost like you are trying to hide something or run something without anyone knowing where it is located. If this is for backup that makes no sense at all.

                                    Tell us what the true outcome of this batch file is supposed to be.

                                    foxidrive



                                      Specialist
                                    • Thanked: 268
                                    • Experience: Experienced
                                    • OS: Windows 8
                                    Re: New member, New DOS adventurer.
                                    « Reply #37 on: January 24, 2014, 12:48:59 AM »
                                    Why I have to explain all this is beyond me!!

                                    You should realise that people here give their time and experience for free, not asking anything in exchange, but expecting to be told accurate information about the task and any special details, like not wanting temporary files. 

                                    On that point the explanation you gave about temporary files seemed unlikely, and you've now said the task is just for home use so it makes even less sense.
                                    You also used the term 'clients' to begin with as if it was a business project.

                                    IDK which part of your explanations are to be believed.  Maybe none.

                                    robertwig

                                      Topic Starter


                                      Rookie
                                    • The Dos and Don'ts of my new life
                                      • Experience: Beginner
                                      • OS: Windows 7
                                      Re: New member, New DOS adventurer.
                                      « Reply #38 on: January 24, 2014, 05:05:17 AM »
                                      You should realise that people here give their time and experience for free, not asking anything in exchange, but expecting to be told accurate information about the task and any special details, like not wanting temporary files. 

                                      On that point the explanation you gave about temporary files seemed unlikely, and you've now said the task is just for home use so it makes even less sense.
                                      You also used the term 'clients' to begin with as if it was a business project.

                                      IDK which part of your explanations are to be believed.  Maybe none.

                                      Let me try and make this clear since you seem to be more concerned with how I use the program and whether it is in a subversive manner rather than focusing on the coding issue. Yes it is for family use to backup game a games forlder. If that works successfully I may make the batch file available to others (non family) to do the same through a games forum we  belong to, hence the term clients is a generic term I used in one of my description.

                                      your comment "If this is a program that you are going to use on your family's computers and network to do some kind of backup why are we screwing around with trying to search and destroy for your program on every drive letter that might be connected to the system? " implies the program is doing a "search and destroy" an assumption you have come to which is not reflected in any of the code I have put forward to date and is unfounded. Almost every piece of code that you guys help with could be used subversively if the end user wanted to do so. You have read my comments about family, clients, not wanting to use temp files and drawn your own conclusions which are off base.

                                      You stated: "You should realise that people here give their time and experience for free, not asking anything in exchange, but expecting to be told accurate information about the task and any special details, like not wanting temporary files."
                                      I realize and appreciate that fact and I did give accurate information as to what I expected from the code, but in my mind at the time I was thinking of everything bein internal. It never occured to me that temp files would be used. I personally think code kept internal is cleaner. If that is not your opinion that is fine but don't jump of the deep end and assume it has some kind of subversive intention.

                                      I hope this has clarified things, but I doubt it. You seem to be on some kind of mission, anyway let's put this rant to bed and either get on with things or not. Thanks.   


                                      foxidrive



                                        Specialist
                                      • Thanked: 268
                                      • Experience: Experienced
                                      • OS: Windows 8
                                      Re: New member, New DOS adventurer.
                                      « Reply #39 on: January 24, 2014, 07:00:03 AM »
                                      Do make sure you attribute quotes to the right person, there's a good chap.

                                      Several people have commented on this to you.

                                      Squashman



                                        Specialist
                                      • Thanked: 134
                                      • Experience: Experienced
                                      • OS: Other
                                      Re: New member, New DOS adventurer.
                                      « Reply #40 on: January 24, 2014, 07:10:04 AM »
                                      If it is a backup program there is no reason at all to not have the path to the script hard coded.

                                      robertwig

                                        Topic Starter


                                        Rookie
                                      • The Dos and Don'ts of my new life
                                        • Experience: Beginner
                                        • OS: Windows 7
                                        Re: New member, New DOS adventurer.
                                        « Reply #41 on: January 24, 2014, 09:49:55 AM »
                                        If it is a backup program there is no reason at all to not have the path to the script hard coded.

                                        You suggestions makes it necessary to predetermine on which drive the folders are installed and that would not be very flexible would it. A utility program should be more dynamic should it not?

                                        Squashman



                                          Specialist
                                        • Thanked: 134
                                        • Experience: Experienced
                                        • OS: Other
                                        Re: New member, New DOS adventurer.
                                        « Reply #42 on: January 24, 2014, 10:19:44 AM »
                                        You suggestions makes it necessary to predetermine on which drive the folders are installed and that would not be very flexible would it. A utility program should be more dynamic should it not?
                                        That is what registry settings and INI files are for.

                                        Squashman



                                          Specialist
                                        • Thanked: 134
                                        • Experience: Experienced
                                        • OS: Other
                                        Re: New member, New DOS adventurer.
                                        « Reply #43 on: January 24, 2014, 10:23:53 AM »
                                        Some script has to be located on your family members computer for them to execute for the utility to work.  How will it execute if nobody knows where it is.  You need some script on the person's computer that you actually KNOW where it is in order to execute all these commands.  You can't just blindly launch this script without knowing where it is.

                                        robertwig

                                          Topic Starter


                                          Rookie
                                        • The Dos and Don'ts of my new life
                                          • Experience: Beginner
                                          • OS: Windows 7
                                          Re: New member, New DOS adventurer.
                                          « Reply #44 on: January 24, 2014, 11:05:19 AM »
                                          Some script has to be located on your family members computer for them to execute for the utility to work.  How will it execute if nobody knows where it is.  You need some script on the person's computer that you actually KNOW where it is in order to execute all these commands.  You can't just blindly launch this script without knowing where it is.

                                          They would create a shortcut on their desktop for the batch utility and execute it whenever they felt the need to backup.

                                          Salmon Trout

                                          • Guest
                                          Re: New member, New DOS adventurer.
                                          « Reply #45 on: January 24, 2014, 11:18:21 AM »
                                          Every user on a Windows machine has a folder pointed to by the %temp% and %tmp% system variables, which is specifically intended for this type of use.

                                          Squashman



                                            Specialist
                                          • Thanked: 134
                                          • Experience: Experienced
                                          • OS: Other
                                          Re: New member, New DOS adventurer.
                                          « Reply #46 on: January 24, 2014, 11:47:22 AM »
                                          They would create a shortcut on their desktop for the batch utility and execute it whenever they felt the need to backup.
                                          But that would create a temporary file on their computer.  You said you didn't want to have anything on their computer.

                                          robertwig

                                            Topic Starter


                                            Rookie
                                          • The Dos and Don'ts of my new life
                                            • Experience: Beginner
                                            • OS: Windows 7
                                            Re: New member, New DOS adventurer.
                                            « Reply #47 on: January 24, 2014, 01:37:05 PM »
                                            But that would create a temporary file on their computer.  You said you didn't want to have anything on their computer.
                                            Yes I said exactly that I didn't want the program to create a temporary file on their computer. The program will locate their file and create the backup on the server. Didn't I outline this in a previous reply or am I mistaken?

                                            robertwig

                                              Topic Starter


                                              Rookie
                                            • The Dos and Don'ts of my new life
                                              • Experience: Beginner
                                              • OS: Windows 7
                                              Re: New member, New DOS adventurer.
                                              « Reply #48 on: January 24, 2014, 01:39:44 PM »
                                              Every user on a Windows machine has a folder pointed to by the %temp% and %tmp% system variables, which is specifically intended for this type of use.

                                              I'm not familiar with this. I will look for a description of it. Thanks

                                              robertwig

                                                Topic Starter


                                                Rookie
                                              • The Dos and Don'ts of my new life
                                                • Experience: Beginner
                                                • OS: Windows 7
                                                Re: New member, New DOS adventurer.
                                                « Reply #49 on: January 24, 2014, 04:01:22 PM »
                                                Folks;

                                                I thank you for your assistance. I now have a working batch file that meets my needs. You can consider this thread closed.
                                                Have a great day.


                                                foxidrive



                                                  Specialist
                                                • Thanked: 268
                                                • Experience: Experienced
                                                • OS: Windows 8
                                                Re: New member, New DOS adventurer.
                                                « Reply #50 on: January 26, 2014, 03:23:15 AM »
                                                You don't know what a %temp% folder is?  My god, you're driving a computer unlicensed! ;)

                                                Raven19528



                                                  Hopeful
                                                • Thanked: 30
                                                  • Computer: Specs
                                                  • Experience: Experienced
                                                  • OS: Windows 7
                                                  Re: New member, New DOS adventurer.
                                                  « Reply #51 on: January 26, 2014, 10:23:20 PM »
                                                  It seems that you were looking for environmental variables that are available in the command prompt. You can get a good listing of these variables and what they are on your system by opening a cmd window and typing the command set.

                                                  As far as the forum is concerned, it is true we all donate time and expertise with no expectation of reward. And while we cannot be charged with wrongdoing if someone were to use our advice for nefarious purposes, we also do not like to think that we are willingly helping anybody who may have nefarious purposes in mind. This is why you may have felt you were being scrutinized so intently, because in all honesty, making something completely "Stealth" is not usually a requirement unless there is something the programmer doesn't want the end user to be aware of. It has a very bad feeling to it to those of us who have worked the programming side for any period of time.

                                                  My suggestion for future requests, should you have any, would be that honesty is truly the best policy. Be blunt and always try to give as much information as you can. This forum is not to provide corporate solutions, but if someone is up front about them trying to figure out s particular solution for their job, they may get a PM from someone with a few suggestions. We don't need to know exact pathnames if it is irrelevant to the program, or how your network is constructed of it is irrelevant. But if we feel you are hiding something, alarm bells start going off and we get very wary of what is being asked.

                                                  Apologies if you felt offended, and please realize that it wasn't personal at all. 
                                                  "All things that are
                                                  Are with more spirit chased than enjoy'd" -Shakespeare

                                                  patio

                                                  • Moderator


                                                  • Genius
                                                  • Maud' Dib
                                                  • Thanked: 1769
                                                    • Yes
                                                  • Experience: Beginner
                                                  • OS: Windows 7
                                                  Re: New member, New DOS adventurer.
                                                  « Reply #52 on: January 27, 2014, 09:30:17 AM »
                                                  Quote
                                                  As far as the forum is concerned, it is true we all donate time and expertise with no expectation of reward. And while we cannot be charged with wrongdoing if someone were to use our advice for nefarious purposes, we also do not like to think that we are willingly helping anybody who may have nefarious purposes in mind.

                                                  This is inherently false which is why we take the cautious tone we do here...
                                                  There have been Forums shut down tons of times over the years on top of in some cases the Forum owners being litigated against and in extreme cases even incarcerated...

                                                  So we don't take it lightly at all...
                                                  " Anyone who goes to a psychiatrist should have his head examined. "

                                                  Salmon Trout

                                                  • Guest
                                                  Re: New member, New DOS adventurer.
                                                  « Reply #53 on: January 27, 2014, 11:15:47 AM »
                                                  I think a further point needs to be made, which is that this forum is not just a dialogue (or "dialog") between an original poster and a series of others, where a question might or might not be designed to get help to do something bad or irresponsible. The forum (all of it) is indexed by search engines such as Google. That means that you can type in a search term and one of the Google hits could well be a post on here. That means that everything that is posted here is available for anybody in the world to find. Example:

                                                  https://www.google.com/search?q=split%20string%20in%20lua

                                                  Some things are definitely out of bounds from the start, such as "How can I hack someone's email" and "how can I crack a password", "How can I get a pirate version of xyz software?" etc. Other questions might seem innocent, and might even be innocently intended, but the answers might involve exposing security holes or could be exploited by others with less worthy motives. Because (luckily) this forum has a core of responsible members, certain questions will raise doubts and cause questions to be asked. Responding to these in an incomplete or petulant fashion will not help.

                                                  Squashman



                                                    Specialist
                                                  • Thanked: 134
                                                  • Experience: Experienced
                                                  • OS: Other
                                                  Re: New member, New DOS adventurer.
                                                  « Reply #54 on: January 27, 2014, 11:25:40 AM »
                                                  And if anyone has been reading the news lately, Google is constantly being sued to take search links down to images and information.

                                                  patio

                                                  • Moderator


                                                  • Genius
                                                  • Maud' Dib
                                                  • Thanked: 1769
                                                    • Yes
                                                  • Experience: Beginner
                                                  • OS: Windows 7
                                                  Re: New member, New DOS adventurer.
                                                  « Reply #55 on: January 27, 2014, 12:56:51 PM »
                                                  Well stated Salmon...Kudo's.
                                                  " Anyone who goes to a psychiatrist should have his head examined. "

                                                  Salmon Trout

                                                  • Guest
                                                  Re: New member, New DOS adventurer.
                                                  « Reply #56 on: January 27, 2014, 01:16:20 PM »
                                                  I've mentioned this before, but the moderators at the AutoIt forum don't take any prisoners. They especially don't like any discussion at all about game bots. All moderation resulting in bans or suspensions is made public...

                                                  Quote
                                                  Insulting Moderators who ask you not to bump is one thing - insulting them a second time in the same thread is just not on. You are banned for a week - use this time to consider how you will behave when and if you return, because continuing as you are will result in your permanent removal from the community.

                                                  Quote
                                                  Since Jos banned you for 5 days yesterday it appears that since being banned you have been PMing other members asking for help and annoying them on "soshul meedja" as well. As you obviously have no intention of behaving in a suitable manner I see no point in you remaining part of this community - permanently banned.

                                                  Quote
                                                  You have been warned before about posting in a completely unintelligible manner. The rubbish you have been adding to the forum this morning is just not acceptable - I have removed most of it. As a result you will be unable to post for one calendar month - and when you return you will be on permanent Moderator queue so your posts can be vetted before they pollute the forum in future.

                                                  Please note that if you do not change your behaviour this time then you will be permanently removed from the community.

                                                  Quote
                                                  Have a week's holiday to reflect on how to conduct yourself in public forums. When and if you return, behave in a reasonable fashon or you will be removed permanently.

                                                  Raven19528



                                                    Hopeful
                                                  • Thanked: 30
                                                    • Computer: Specs
                                                    • Experience: Experienced
                                                    • OS: Windows 7
                                                    Re: New member, New DOS adventurer.
                                                    « Reply #57 on: January 28, 2014, 05:25:48 PM »
                                                    This is inherently false which is why we take the cautious tone we do here...
                                                    There have been Forums shut down tons of times over the years on top of in some cases the Forum owners being litigated against and in extreme cases even incarcerated...

                                                    So we don't take it lightly at all...
                                                    That's true. Sorry, I was thinking in terms of those contributing to the forum and not the owners. Yes forums have been shut down, I've seen it happen more than once. I, for one, enjoy this forum and would appreciate it not being taken down, especially over some "innocent" questions.
                                                    "All things that are
                                                    Are with more spirit chased than enjoy'd" -Shakespeare