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

Author Topic: Batch file move folder from current directory command  (Read 23996 times)

0 Members and 1 Guest are viewing this topic.

dream08

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Windows 7
    Batch file move folder from current directory command
    « on: January 09, 2011, 11:52:34 AM »
    I want to move  (example) the folder (1222) from location: (C:\Users\USER\Desktop\aoto)  to the destination (C:\Program Files) running the

    bat file from (C:\Users\USER\Desktop\aoto) but without entering: (C:\Users\USER\Desktop\aoto\1222) i dont want to enter the full folder to move path

    but just enter the folder name and enter full destination path (C:\Program Files) because i want the folder (aoto) that contains (1222) to be located

    anywhere with the bat file command still able to work no matter where the source is how do i do this.


    i just want a command like this    move "c:\my src" "c:\src files\new src"   but without having to put "c:\my src" and just something like "my src" to

    move from this directory.


    « Last Edit: January 09, 2011, 12:08:59 PM by dream08 »

    donpage



      Rookie

      Thanked: 1
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows XP
      Batch file move folder from current directory command
      « Reply #1 on: January 09, 2011, 11:59:54 AM »

      C:\>path /?
      Displays or sets a search path for executable files.

      PATH [[drive:]path[;...][;%PATH%]
      PATH ;

      Type PATH ; to clear all search-path settings and direct cmd.exe to search
      only in the current directory.
      Type PATH without parameters to display the current path.
      Including %PATH% in the new path setting causes the old path to be
      appended to the new setting.

      C:\>xcopy /?

      dream08

        Topic Starter


        Greenhorn

        • Experience: Beginner
        • OS: Windows 7
        Re: Batch file move folder from current directory command
        « Reply #2 on: January 09, 2011, 12:05:43 PM »
        I'm still confused i just want a command like this           move "c:\my src" "c:\src files\new src"       

        but without having to put "c:\my src" and just something like "my src" to move from this directory.

        donpage



          Rookie

          Thanked: 1
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows XP
          Batch file move folder from current directory command
          « Reply #3 on: January 09, 2011, 12:18:47 PM »
          I'm still confused i just want a command like this           move "c:\my src" "c:\src files\new src"       

          but without having to put "c:\my src" and just something like "my src" to move from this directory.

          Code: [Select]
          @echo off
          cd c:\test
          cd src

          copy "*.*"   "c:\srcfiles\new src\"

          dream08

            Topic Starter


            Greenhorn

            • Experience: Beginner
            • OS: Windows 7
            Re: Batch file move folder from current directory command
            « Reply #4 on: January 09, 2011, 12:35:00 PM »
            I'm still stuck !  :o

            I just tried this
            Code: [Select]
            @echo off
            cd c:\test
            cd src

            copy "*.*" "C:\Program Files"

            and it started copying loads of random files to program files .
            i also tried
            Code: [Select]
            @echo off
            cd c:\test
            cd src

            copy "1222" "C:\Program Files"

            and it didnt work i hope you can see what i'm trying to do here.

            donpage



              Rookie

              Thanked: 1
              • Computer: Specs
              • Experience: Experienced
              • OS: Windows XP
              Re: Batch file move folder from current directory command
              « Reply #5 on: January 09, 2011, 01:00:13 PM »
              I hope you can see what I'm trying to do here.

              I do not understand.

              I will back off and allow someone else to answer your question.

              Good Luck

              dream08

                Topic Starter


                Greenhorn

                • Experience: Beginner
                • OS: Windows 7
                Re: Batch file move folder from current directory command
                « Reply #6 on: January 09, 2011, 01:08:50 PM »
                I do not understand.

                I will back off and allow someone else to answer your question.

                Good Luck
                Thanks for your attemt to help me please reply if you have any more ideas, to try and explain more i just need to use the move command

                without it being specific to type the full path to the folder to be moved instead just moving the folder which resides in the same folder as the bat file 

                *so without typing      move "C:\Users\USER\Desktop\aoto\1222" "C:\Program Files"   which moves folder 1222 to C:\Program Files i want the bat file

                to be universal so no matter where \aoto\ is located it will move 1222 to C:\Program Files. For example if \aoto\ wasn't on the desktop

                move "C:\Users\USER\Desktop\aoto\1222" "C:\Program Files" wouldn't work.

                dream08

                  Topic Starter


                  Greenhorn

                  • Experience: Beginner
                  • OS: Windows 7
                  Re: Batch file move folder from current directory command
                  « Reply #7 on: January 09, 2011, 02:44:56 PM »
                  Help :-\

                  Salmon Trout

                  • Guest
                  Re: Batch file move folder from current directory command
                  « Reply #8 on: January 09, 2011, 11:55:47 PM »
                  The folder that a batch is located in is referenced by "%~dp0" so you could do this

                  Code: [Select]
                  if not exist "C:\Program Files\1222" md "C:\Program Files\1222"
                  move "%~dp0\1222\*.*" "C:\Program Files\1222"


                  dream08

                    Topic Starter


                    Greenhorn

                    • Experience: Beginner
                    • OS: Windows 7
                    Re: Batch file move folder from current directory command
                    « Reply #9 on: January 10, 2011, 01:42:48 PM »
                    The folder that a batch is located in is referenced by "%~dp0" so you could do this

                    Code: [Select]
                    if not exist "C:\Program Files\1222" md "C:\Program Files\1222"
                    move "%~dp0\1222\*.*" "C:\Program Files\1222"
                    Thanks  ::)

                    jyra

                    • Guest
                    Re: Batch file move folder from current directory command
                    « Reply #10 on: January 21, 2011, 08:27:02 AM »
                    I just did a similar task using cd /d %~dp0 and it worked great. However, I converted the .bat into an .exe and when I execute the .exe the %~dp0 leads to the temp folder instead. Is there a way to edit the cd /d %~dp0 to the current directory of the .exe that is launching?

                    Sidewinder



                      Guru

                      Thanked: 139
                    • Experience: Familiar
                    • OS: Windows 10
                    Re: Batch file move folder from current directory command
                    « Reply #11 on: January 21, 2011, 09:05:30 AM »
                    Welcome to Computer Hope. Please do not hijack another poster's thread. Start you own for better service.

                    What program are you using for the bat to exe conversion? Many Most of them cannot handle many of the NT extensions to batch language.

                    Why are you converting batch files? Batch code is designed to be run from the command line as a text file. Introducing conversions to exe or double clicking from Explorer only add layers of complexity that can be difficult to debug.

                     8)



                    The true sign of intelligence is not knowledge but imagination.

                    -- Albert Einstein

                    Salmon Trout

                    • Guest
                    Re: Batch file move folder from current directory command
                    « Reply #12 on: January 21, 2011, 09:17:46 AM »
                    the %~dp0 leads to the temp folder instead. Is there a way to edit the cd /d %~dp0 to the current directory of the .exe that is launching?

                    All these bat-to-exe "compilers" do is enclose the batch script in an .exe wrapper. When you run the exe it extracts the original batch script to (as it appears in your case) the temp folder and runs it from there. Therefore %~dp0 will always be the temp folder. So why does it have to be an exe?