Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. batch file and xcopy question

batch file and xcopy question

Scheduled Pinned Locked Moved The Lounge
helpquestion
22 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dan Neely

    Then how do I get the folder the batchfile is in so I can get the paths correctly? As a last resort I can hardcode the paths into the file, but that would break the .bat any time the user decided that instead of installing to to C:\prog files\default_install_folder\ he wanted it in C:\prog files\Somewhere_else\

    R Offline
    R Offline
    Roland Pibinger
    wrote on last edited by
    #9

    dan neely wrote:

    Then how do I get the folder the batchfile is in so I can get the paths correctly?

    Pass the install path as argument to the bat file, eg:

    REM mybat.bat
    ECHO the install directory is %1

    call it:

    mybat.bat C:\Somewhere_else

    1 Reply Last reply
    0
    • N Nish Nishant

      DavidCrow wrote:

      What exactly is your question?

      I thought his problem was pretty obvious. :-) Regards, Nish


      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
      The Ultimate Grid - The #1 MFC grid out there!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #10

      Nishant Sivakumar wrote:

      I thought his problem was pretty obvious.

      Well, I didn't.


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      1 Reply Last reply
      0
      • N Nish Nishant

        Run the batch file from the folder containing it. Regards, Nish


        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
        The Ultimate Grid - The #1 MFC grid out there!

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #11

        The level of user I'm dealing with needs open folder X, double click on the icon level instructions. Not goto start-run, etner cmd.exe, type cd type level instructions.

        J 1 Reply Last reply
        0
        • D Dan Neely

          I'm trying to do some file copying using a batchfile, but am stuck on the issue of relative paths. I want to copy from \source to \dest, wehre is the arbitrary folder the batch file and source folder are located in. If I hardcode an absolute path into the xopy it works fine, but any type of relative path is linked to C:\windows\, and not the location of the batchfile.

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #12

          %~dp0 That expands to the path where the batch file is located. So, assuming you drop into c:\gimlets a batchfile containing:

          copy "%~dp0MyFile.txt" "%~dp0\backups\"

          ..it'll copy c:\gimlets\MyFile.txt to c:\gimlets\backups\MyFile.txt. :) Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

          ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

          D S 2 Replies Last reply
          0
          • D Dan Neely

            I assume you meant .\ since the other one is used to flag a command. I did try this, it still does the path relative to the location of cmd.exe (C:\windows\), not the folder the batfile I doubleclicked on is located..

            J Offline
            J Offline
            Jeremy Falcon
            wrote on last edited by
            #13

            dan neely wrote:

            I assume you meant .\ since the other one is used to flag a command.

            You are correct. I'm too used to working in Unix for the command line. :laugh:

            dan neely wrote:

            I did try this, it still does the path relative to the location of cmd.exe (C:\windows\), not the folder the batfile I doubleclicked on is located..

            I see what you're saying. Well in that case, as was said already, it uses the CWD. Even running the batch file in the same dir won't work if the CWD isn't set to the dir you need it to be in. What you'll need to do then is pass the directory as a parameter to the batch file so the batch file can resolve the full directory for the xcopy command. Jeremy Falcon

            1 Reply Last reply
            0
            • D Dan Neely

              The level of user I'm dealing with needs open folder X, double click on the icon level instructions. Not goto start-run, etner cmd.exe, type cd type level instructions.

              J Offline
              J Offline
              Jeremy Falcon
              wrote on last edited by
              #14

              If that's the case then the CWD should be set already. Instead of using the command prompt, creat a batch file using the ./ and double it's icon in explorer (the batch file should be in the dir where you want your relative starting point to be). Jeremy Falcon

              1 Reply Last reply
              0
              • S Shog9 0

                %~dp0 That expands to the path where the batch file is located. So, assuming you drop into c:\gimlets a batchfile containing:

                copy "%~dp0MyFile.txt" "%~dp0\backups\"

                ..it'll copy c:\gimlets\MyFile.txt to c:\gimlets\backups\MyFile.txt. :) Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

                ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #15

                Shog9 wrote:

                Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

                Cool, that's exactly what I was looking for. Where is the windows helpfile hidden. Having looked at it before I assumed someone as MS decided writing worthless help was one area they could easily surpass *nix and purged where i found it from my memory.

                S N S 3 Replies Last reply
                0
                • D Dan Neely

                  Shog9 wrote:

                  Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

                  Cool, that's exactly what I was looking for. Where is the windows helpfile hidden. Having looked at it before I assumed someone as MS decided writing worthless help was one area they could easily surpass *nix and purged where i found it from my memory.

                  S Offline
                  S Offline
                  Shog9 0
                  wrote on last edited by
                  #16

                  dan neely wrote:

                  Where is the windows helpfile hidden.

                  On XP, it's called the "Help and Support Center", and initially, there's a link to it from the Start menu. Not sure about previous versions of Windows, i don't really remember ever using it.

                  ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                  1 Reply Last reply
                  0
                  • S Shog9 0

                    %~dp0 That expands to the path where the batch file is located. So, assuming you drop into c:\gimlets a batchfile containing:

                    copy "%~dp0MyFile.txt" "%~dp0\backups\"

                    ..it'll copy c:\gimlets\MyFile.txt to c:\gimlets\backups\MyFile.txt. :) Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

                    ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                    S Offline
                    S Offline
                    Somanova420
                    wrote on last edited by
                    #17

                    Well that's so easy we all should've been born knowing that. %~dp0 <--- Who came up with that

                    D S 2 Replies Last reply
                    0
                    • S Somanova420

                      Well that's so easy we all should've been born knowing that. %~dp0 <--- Who came up with that

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #18

                      Hey it's something you'll never forget. You can't forget something you never were able to remember in the first place. :-/

                      S 1 Reply Last reply
                      0
                      • D Dan Neely

                        Shog9 wrote:

                        Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

                        Cool, that's exactly what I was looking for. Where is the windows helpfile hidden. Having looked at it before I assumed someone as MS decided writing worthless help was one area they could easily surpass *nix and purged where i found it from my memory.

                        N Offline
                        N Offline
                        Nish Nishant
                        wrote on last edited by
                        #19

                        Yeah, those are pretty handy. BTW just as %~dp0 returns the full path, %~dpnx0 returns the full path with filename. Regards, Nish


                        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                        The Ultimate Grid - The #1 MFC grid out there!

                        1 Reply Last reply
                        0
                        • S Somanova420

                          Well that's so easy we all should've been born knowing that. %~dp0 <--- Who came up with that

                          S Offline
                          S Offline
                          Shog9 0
                          wrote on last edited by
                          #20

                          :shrug: If you want intuitive, stay clear of the command line. Cryptic incantations with vast, irreversible results - it's the power we're after here, boy! :)

                          ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                          1 Reply Last reply
                          0
                          • D Dan Neely

                            Hey it's something you'll never forget. You can't forget something you never were able to remember in the first place. :-/

                            S Offline
                            S Offline
                            Somanova420
                            wrote on last edited by
                            #21

                            Good point :-O

                            1 Reply Last reply
                            0
                            • D Dan Neely

                              Shog9 wrote:

                              Read up on batchfiles and cmd.exe in the windows help files sometime. It's just about the only useful thing in those helpfiles after all, you might as well get your money's worth...

                              Cool, that's exactly what I was looking for. Where is the windows helpfile hidden. Having looked at it before I assumed someone as MS decided writing worthless help was one area they could easily surpass *nix and purged where i found it from my memory.

                              S Offline
                              S Offline
                              Stuart Dootson
                              wrote on last edited by
                              #22

                              dan neely wrote:

                              Where is the windows helpfile hidden

                              Click on the desktop and press F1 is the way I get at it, then search for 'for' or 'if', to get to the command processor reference.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups