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

Author Topic: copy all files and folders from current folder  (Read 27000 times)

0 Members and 1 Guest are viewing this topic.

mioo_sara

    Topic Starter


    Intermediate

    copy all files and folders from current folder
    « on: April 01, 2012, 12:12:48 AM »
    hi my friend
     i have a simple question for you profesionals :)

     i found lots of batch files that can copy files or folders but i need a special one
    first of all i have more than 3000 folders including subfolder in my multi hard drives so i dont want to type each folder name or its drive name so i added my batch file to right click of my mouse
    i want every time that i execute my batch in any of my folders it scan files and folders names including subfolders and make a report.text file
    then copy these files and folders from current folder to a new destination d:\bacup
    how can i do it
    i would be very glad if you write a batch script for me
    by the way i found lots of batch file but none of them was the write one
    thanks

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: copy all files and folders from current folder
    « Reply #1 on: April 01, 2012, 12:51:22 PM »
    First, an opinion
    Begin IMHO
      DOS is dead. 
      For some things it still is quick and easy,
      - but so is Duct Tape.
    End of IMHO
    Some basic DOS things your mother did not tell you about.
    This command shows ONLY directories below the current:
    Code: [Select]
    DIR /AD Same thing, but no details
    Code: [Select]
    DIR /AD /B Same thing, but get the lower levels too.
    Code: [Select]
    DIR /AD /B /S
    Remember, it starts in the current directory. start from a higher nor lower level and get different results.

    This example gets all l files of all types, full path name. But never name of just the directory itself.
    Code: [Select]
    DIR /A-D /B /S
    Now add re-direction to put it into a file.
    Code: [Select]
    DIR /A-D /B /S > MyList.txt
    You can edit MyList.txt with notepad, or your favorite text editor.
    You can quickly make it into a master batch file. You can block exceptions by putting REM at the start of a line you want to skip.

    Does this give you some ideas?

    mioo_sara

      Topic Starter


      Intermediate

      Re: copy all files and folders from current folder
      « Reply #2 on: April 01, 2012, 01:45:01 PM »
      thanks for your answer dear

      i have a batch script
      its working but not the way i want !! :P
      i dont know why  it copy  but the structures of destination folders and files  are not the same as source !
      i mean it copy lots of files out of their  folders  and some subfolders never copid !!
      those were not read only  or system  type ! ???
      have a look  at script  and see if can help? ;)
      Quote
      @echo off
      dir/s/b/ad | find/v "()"> filelist.txt
      FOR /F "skip=1 eol= tokens=* delims= usebackq" %%i IN (filelist.txt) DO xcopy/e/y/c "%%i" d:\backup

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: copy all files and folders from current folder
      « Reply #3 on: April 01, 2012, 02:54:15 PM »
      Not sure why you need a file listing to key off of. I used a drag and drop template to create this. If it's attached to the context menu, it just might work:

      Code: [Select]
      @echo off
      setlocal

      xcopy /e /c /y %1 d:\Backup

      Good luck. 8)

      Quote
      Begin IMHO
        DOS is dead.
        For some things it still is quick and easy,
        - but so is Duct Tape.
      End of IMHO

      DOS is dead? When did this happen? How tragic. Was it a beautiful service?  I wonder how my 27yo IBM-AT running PC-DOS 7 will take this news; at his age most of his friends are gone.

      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: copy all files and folders from current folder
      « Reply #4 on: April 01, 2012, 03:56:41 PM »
      Really, it is not my opinion at all.  :o

      Look at this article, from late last year. His dry sarcastic wit makes then point.
      Quote
      DOS Will Never Die!
      By Dan Mabbutt, About.com Guide   August 29, 2011
      A continutation of a popular (?) series.
      The last time I wrote a blog like this, I got some serious kickback.
      "It's already dead, Doofus! DOS hasn't been needed for Windows since Windows 3.1!"
      "Do you see DOS anywhere in Windows? Repeat after me: C-O-M-M-A-N-D P-R-O-M-P-T."
      Yeah, yeah, yeah. If it DIR's like DOS and ECHO's like DOS, then it is DOS. Writing "Command Prompt" all the time gives me carpal tunnel.
      ...

      ......
      I rest my case.

      mioo_sara

        Topic Starter


        Intermediate

        Re: copy all files and folders from current folder
        « Reply #5 on: April 01, 2012, 11:32:37 PM »
        dear Sidewinder
        thanks but your cod is not working

        Quote
        0 File(s) copied
        Press any key to continue . .
        .

        by the way i dont want to copy just files i want to copy all the files and folders including subfolders from current folder to d:\Backup

        Quote
        Not sure why you need a file listing to key off of. I used a drag and drop template to create this. If it's attached to the context menu

        its port of a bigger program my friend its not just a copy

        Salmon Trout

        • Guest
        Re: copy all files and folders from current folder
        « Reply #6 on: April 02, 2012, 12:05:04 AM »
        I rest my case.

        That guy is a fool.


        mioo_sara

          Topic Starter


          Intermediate

          Re: copy all files and folders from current folder
          « Reply #7 on: April 02, 2012, 12:55:18 AM »
          guys please just answer my  question ???  you  have all the time to fight ! ;D

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: copy all files and folders from current folder
          « Reply #8 on: April 02, 2012, 01:28:38 AM »
          Making backups is best done with a backup program.

          To make it easy to understand, I shall use some metaphors. If you skip a step, it gets very bad. so detail is important.

          A backup program is like hiring a moving company to stuff your stuff into a van.
          You stuff in smashed into a big box and sent somewhere and you have to unpack it. Ugh!

          Use the right DOS command is more like the transporter in Star Trek. You get an exact duplicate in another place

          When you wish to replicate an entire content of one folder tree to another folder, there is a method using XCOPY. The destination folder should be empty if you put nit in a batch file.

          You must understand how XCOPY works. Try XCOPY /? for help.

          You need to understand the idea of 'current folder' in DOS.

          Let's say the D: drive has a folder named 'Boston' and is the place I want to start.
          And the E: has a folder named 'Chicago' and is where I wnat to replicate all the streets and cars found in 'Boston' using a single command.
          First I got to 'Boston' and look around.
          Code: [Select]
          D:
          CD BOSTON
          DIR
          Looks good.
          Now I look at 'Chicago and make sure it is empty. If not, failure is probable.
          Code: [Select]
          E:
          CD CHICAGO
          DIR
          OK. Coast is clear.
          Now return to the source drive. Don't change anything.
          Code: [Select]
          D:At this point the default directory on E: is  'Chicago' and I and now on 'Boston' on D:
          Now I give this command at the DOS prompt.
          Code: [Select]
          XCOPY D: E: /E /H
          This post is not intended to be annoying. Using DOS commands is not very intuitive. This is the best I know how to do at explaining.  Use of metaphors makes things easier that using the technical names of things.

          If XCOPY does not work for you, please come back.

          Microsoft DOS xcopy command





          mioo_sara

            Topic Starter


            Intermediate

            Re: copy all files and folders from current folder
            « Reply #9 on: April 02, 2012, 04:16:28 AM »
             :)dear Geek-9pm
            thanks for your help  and your teaching
            but wish you  had a look at my   post number 3 :P
            you  can  see that i used xcopy command and its working now !! :( but cuz source folder is changing every day so program should find the source folder (that is my  current folder)  and copy any folder and files from there to destination folder (d:\backup)
            something else this script will  be used in  another program later

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: copy all files and folders from current folder
            « Reply #10 on: April 02, 2012, 09:27:47 AM »
            Quote
            i found lots of batch files that can copy files or folders but i need a special one
            first of all i have more than 3000 folders including subfolder in my multi hard drives so i dont want to type each folder name or its drive name so i added my batch file to right click of my mouse

            Please explain more about where you click the right mouse button. If you're in Explorer then I doubt you can select a folder and retrieve the path for your batch file (not easily anyways). VBScript has a BrowseForFolder method which could pass back a selected folder path on the console. The batch file could retrieve the value and use it in the XCOPY command. You might also use the %cd% variable but you might be surprised at the value when running from the context menu.

            Note that the VBScript solution would be interactive which you may not want in a batch file.

             8)

            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            mioo_sara

              Topic Starter


              Intermediate

              Re: copy all files and folders from current folder
              « Reply #11 on: April 02, 2012, 09:58:39 AM »
              dear Sidewinder :)
              no mater where i  right click (on a file of folder when i right click )i can see my batch
              so you guess batch is in current folder and i want to run it so it should copy whatever (folders and files) to destination folder (d:\backup)
              i hope i could explain what i'm  looking for :)
              have a look  at post #3
              if you change xcopy to move it will work like a charm but unfortunately i want to copy and not move

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              Re: copy all files and folders from current folder
              « Reply #12 on: April 02, 2012, 11:27:55 AM »
              Quote
              no mater where i  right click (on a file of folder when i right click )i can see my batch
              so you guess batch is in current folder

              Maybe I'm just dense but where do you see a file or folder to right click on? You  mentioned you added your batch file to a right mouse click. How? I'm not understanding how clicking a folder would change the current directory. My guess is that you see you batch file as an entry on the context menu not as a member of a folder.

              The only way I see this working with a minimum of craziness, would be to navigate to the directory you want to copy and then run your batch file (use a fully qualified path) from the command prompt.

              Also you may want to pipe a "D" to the xcopy command to prevent a console prompt:

              echo D | xcopy ...

               8)




              The true sign of intelligence is not knowledge but imagination.

              -- Albert Einstein

              mioo_sara

                Topic Starter


                Intermediate

                Re: copy all files and folders from current folder
                « Reply #13 on: April 02, 2012, 01:25:12 PM »
                Quote
                My guess is that you see you batch file as an entry on the context menu
                this is correct my friend  ;D

                i can't see batch name when i right click on folders but just on files
                but you imagine i copid my batch in current folder and run it ok?  ::)  i need to copy all the contents to destination
                i mean both folders and files that are located in the current folder
                i hope i could explain this tragic situation !!! :-X

                Sidewinder



                  Guru

                  Thanked: 139
                • Experience: Familiar
                • OS: Windows 10
                Re: copy all files and folders from current folder
                « Reply #14 on: April 02, 2012, 02:52:59 PM »
                You keep repeating yourself, but I still can't visualize what you are trying to do. Please answer my questions.

                What program is displaying this list of files and folders?

                If you select a folder, and right click the mouse, what do you expect to happen?

                How did you attach the batch file to the context menu. As far as I know, this has to be done thru the registry. Is this what you did?

                Like I mentioned, a combination of VBScript and batch code can do this, but at this point I'm not sure what you really want.

                Gotta go. The radio is playing Zeppelin's Dazed and Confused.  ;D

                The true sign of intelligence is not knowledge but imagination.

                -- Albert Einstein

                Salmon Trout

                • Guest
                Re: copy all files and folders from current folder
                « Reply #15 on: April 02, 2012, 03:43:30 PM »
                If you select a folder, and right click the mouse, what do you expect to happen?

                A context menu which includes Send To should appear, shouldn't it?



                soybean



                  Genius
                • The first soybean ever to learn the computer.
                • Thanked: 469
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 10
                Re: copy all files and folders from current folder
                « Reply #16 on: April 02, 2012, 06:01:36 PM »
                ... but cuz source folder is changing every day so program should find the source folder (that is my  current folder)  and copy any folder and files from there to destination folder (d:\backup) ...
                Why not get a freeware file synchronization/backup program such as Allway Sync - there are others but this is one I've used - and use it to achieve your objective?  Seems to me this would be easier solution than trying to resort to some DOS technique.

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: copy all files and folders from current folder
                « Reply #17 on: April 02, 2012, 06:26:05 PM »
                Why not get a freeware file synchronization/backup program such as Allway Sync - there are others but this is one I've used - and use it to achieve your objective?  Seems to me this would be easier solution than trying to resort to some DOS technique.
                I agree. Some Sync utilities can be invoked with a template to automate a task. That might be called 'batch' programming, but it is not just plain  DOS. Many programs  run from a command line and run a script.

                Example:some programs are written in Excel and use VBA. Such business class programs  backup and archive files that have been imported.  Such are often paid only programs. Some are found on download.com and have free trial.

                But not knowing the intent of the OP, it is hard to know if giving bits and pieces of DOS code if he does not understand how to integrate the parts. And it not clear if he wants to invoke the DoS batch code from the GUI or the command line.

                IMHO the OP needs to read some tutorials on VBscript and Cscript.
                Using the command-based script host (CScript.exe)
                « Last Edit: April 02, 2012, 06:36:50 PM by Geek-9pm »

                mioo_sara

                  Topic Starter


                  Intermediate

                  Re: copy all files and folders from current folder
                  « Reply #18 on: April 02, 2012, 10:21:18 PM »
                  Quote
                  As far as I know, this has to be done thru the registry. Is this what you did?

                  yes i add it thru registry

                  Quote
                  But not knowing the intent of the OP, it is hard to know if giving bits and pieces of DOS code if he does not understand how to integrate the parts. And it not clear if he wants to invoke the DoS batch code from the GUI or the command line.
                  its part of my flash project .unfortunately  flash is so week  for working with windows so i should do the rest with batch programing !
                  i used lots of batches and 80% of the job has done so  i  prefer to do the rest in  this way

                  Geek-9pm


                    Mastermind
                  • Geek After Dark
                  • Thanked: 1026
                    • Gekk9pm bnlog
                  • Certifications: List
                  • Computer: Specs
                  • Experience: Expert
                  • OS: Windows 10
                  Re: copy all files and folders from current folder
                  « Reply #19 on: April 03, 2012, 01:16:38 AM »
                  Quote
                  its part of my flash project .unfortunately  flash is so week  for working with windows so i should do the rest with batch programing !
                  i used lots of batches and 80% of the job has done so  i  prefer to do the rest in  this way

                  Now I am totally confused. You want to flash the  BIOS?
                  No, you want to write a system utility using Adobe Flash. Huh?

                  The natural choice for a Flash app is to extend it with Java. But C# would also work.  Even current versions of Visual Basic control FLASH thing.

                  I have never hears of DOS batch used as a supplement, extension or replacement for Flash. But there is a lot I don't know.  :-X

                  Are you writing a Windows app or a browser app?  Browser apps often use JavaScript, vb-scrip, ActiveX  or even Java at the client side.

                  The DOS batch stuff is essentially twenty years old. With a few improvements in recent years. IMHO it is not well suited for browser apps. It is suited for doing backups and archives and removing dead files. Not so good for doing anything visual.

                  Only 80% of your code works? Did you model the code? You need to get up to 99 % of your code working before working on kinks.
                  Have you verified the logic and sequence of your code?

                  A practice of professional programmers is to write a large part of the code in the best programming tool that they can use. Then fill in the tough spots with things imported from other software tools.

                  I am unable to visualize this with FLASH and DOS batch.
                  Sorry I can not help you with your quest. But keep at it and eventually you will find a solution.  It is not really impossible.

                  Have you ever read books on structured programming? Or books about program design and  incremental refinement ?
                  Books on structured programming with  C#

                  Squashman



                    Specialist
                  • Thanked: 134
                  • Experience: Experienced
                  • OS: Other
                  Re: copy all files and folders from current folder
                  « Reply #20 on: April 03, 2012, 05:52:15 AM »
                  A context menu which includes Send To should appear, shouldn't it?
                  I agree.  Putting it into the SendTo menu which doesn't require a registry edit works perfectly.  I have done that with a few of my batch files over the years.

                  Another option would be to just drag the source folder onto the batch file which would take it as input in the variable %1.

                  Sidewinder



                    Guru

                    Thanked: 139
                  • Experience: Familiar
                  • OS: Windows 10
                  Re: copy all files and folders from current folder
                  « Reply #21 on: April 03, 2012, 05:57:15 AM »
                  OK. Last try. This goes back to the original question as I understand it or at least how I think I understand it. First up is a VBScript to allow the user the select a folder for the XCOPY operation:

                  Code: [Select]
                  Const RETURN_ONLY_FOLDERS = &H0001
                  Const WINDOW_HANDLE = 0
                  Const MY_COMPUTER = 17

                  Set objShell  = CreateObject( "Shell.Application" )
                  Set objFolder = objShell.BrowseForFolder( WINDOW-HANDLE, "Select Folder", RETURN_ONLY_FOLDERS, MY_COMPUTER )

                  'Check For Cancel Button; Nothing Returned
                  '
                  If TypeName(objFolder) <> "Nothing" Then
                    WScript.Echo objFolder.Items.Item.Path
                  End If   

                  Save the script in any folder with any name and a VBS extension.

                  Next up is the batch code. Replace the for statement in your existing batch file with the code below:

                  Code: [Select]
                  set target=D:\Backup
                  for /f "tokens=* delims=" %%i in ('cscript //nologo drive:\path\scriptname.vbs') do (
                    if .%%i NEQ . (echo D | xcopy "%%i" %target% /e /c /y > d:\filelist.txt
                    ) else ( goto :eof )


                  Change drive:\path\scriptname.vbs to point to where you saved the VBS script.

                  The user will be presented with a dialog allowing selection of any folder on the system. Only folders are shown to reduce clutter. Use the left mouse button to highlight the folder name and press OK. The folder path will be returned to the batch file for use by the XCOPY operation. If you CANCEL the folder dialog, the entire batch file will terminate. A file will also be created with a listing of what was copied. (filelist.txt)

                  Feel free to tweak the code as needed.

                  If you find this useful, then great. If not, well then not so great.

                  Exit stage left.  8)
                  « Last Edit: April 03, 2012, 06:51:17 AM by Sidewinder »
                  The true sign of intelligence is not knowledge but imagination.

                  -- Albert Einstein

                  mioo_sara

                    Topic Starter


                    Intermediate

                    Re: copy all files and folders from current folder
                    « Reply #22 on: April 04, 2012, 02:06:32 AM »
                    dear Geek-9pm

                    Quote
                    you want to write a system utility using Adobe Flash. Huh

                    yes . but i don't use latest version(adobe cs4 or 5) i'm using adobe flash 8
                    its rather old but unfortunately  i should use it .in  cs4 or 5 adobe added adobe air so you can  work directly  with the outside world throu java vb or lots of other scripting languages

                    Quote
                    I am unable to visualize this with FLASH and DOS batch

                    adobe flash 8  has not allowed any  command that even think  about executing anything(except media ) even  opening a window in  windows explorer is a big problem ! and you  should do  lots of scripting tricks!! :-X

                    Quote
                    Only 80% of your code works?
                    no  i never said that !!  :o what i mean was my project has reached to  80% and its near to  end

                    by  the way  thanks for the link ;)

                    mioo_sara

                      Topic Starter


                      Intermediate

                      Re: copy all files and folders from current folder
                      « Reply #23 on: April 04, 2012, 02:08:10 AM »
                      dear Squashman

                      please read post below i  think my  bad English  is the problem ! :-\

                      mioo_sara

                        Topic Starter


                        Intermediate

                        Re: copy all files and folders from current folder
                        « Reply #24 on: April 04, 2012, 02:10:48 AM »
                        dear Sidewinder
                        thanks for the time and script that you  wrote for me ;)
                        its working very  nice but wish  it could act automatically it needs final  user to  specify  the source folder . cant it be done by  the program itself?
                        please read my  last post i pot another script and another explain i  think  cuz of my  bad English  i explain the situation awful!! ::)

                        mioo_sara

                          Topic Starter


                          Intermediate

                          Re: copy all files and folders from current folder
                          « Reply #25 on: April 04, 2012, 02:24:44 AM »
                          ok  guys i'm  back again ! ;D
                          sometimes knowing a language is not enough and you should know how to ask !
                          Albert Einstein !!! ;D ;D ;D

                          first of all  sorry  for my  bad English  its my  teacher's  fault !
                          i think i explained a simple question  in a very hard or bad way and i made the situation very hard and so  i did not got what i wanted at the first place
                          now forget about right click or any stupid idea that i said at the post #1( wish i could edit it)
                          now i try to  explain my  question in  a easy  to  understand way


                          lets imagine  we have a folder (named johns) and we want to copy all the files and folders(including sub folders)from johns to  d:\backup
                          that's all  that's what i want !!   :P  so we copy  a batch file to johns  folder and run  it.. now batch should start the copying process .is it that hard for even old fashion Dos base batch file to do? ??? ???
                          now the problem  is that if i could put source folder name (johns) in batch script problem  could be solved but cuz final program will use these batches and source folder name will  be changed in a frequently  time so i prefer that batch  do this job  for me
                          i mean  batch  Dir from  the current folder and copy  any including object to  the destination
                          below you  can  see a simple batch that do this but instead of coping it moves the objects(i don't like this)

                          Quote
                          @echo off
                          cd
                          dir/s/b > filelist.txt
                          for /f "delims=" %%F in (filelist.txt) do move "%%F" "D:\backup"

                          any idea ?
                          « Last Edit: April 04, 2012, 02:48:55 AM by mioo_sara »

                          BC_Programmer


                            Mastermind
                          • Typing is no substitute for thinking.
                          • Thanked: 1140
                            • Yes
                            • Yes
                            • BC-Programming.com
                          • Certifications: List
                          • Computer: Specs
                          • Experience: Beginner
                          • OS: Windows 11
                          Re: copy all files and folders from current folder
                          « Reply #26 on: April 04, 2012, 03:23:28 AM »
                          If it is the current directory you wish to copy, you can specify the current directory using a period (.):

                          For example, let us go with your example; let's say we have a folder Johns on C: drive; Let's say we are writing the batch file to run from within that folder (again, following your example scenario).

                          if we want to copy all files and folders from the current directory, we can use xcopy and the period

                          Code: [Select]
                          xcopy . D:\backup /s /i

                          There is something of a complication: this doesn't necessarily refer to the folder the batch file is in. If  you want to always refer to the folder that the batch is in (as opposed to the current directory of the command prompt session running the batch file) you can use this instead:

                          Code: [Select]
                          xcopy %~dp0 D:\backup /s /i






                          I was trying to dereference Null Pointers before it was cool.

                          mioo_sara

                            Topic Starter


                            Intermediate

                            Re: copy all files and folders from current folder
                            « Reply #27 on: April 04, 2012, 02:03:11 PM »
                            my my my dear BC_Programmer :) thank you  very much  it worked like a charm :)
                            that was a simple but breath taking question ! you really  help  me thank again
                            i was really  becoming disappointed and thought its simple but its not possible with dos !
                            i pressed thanks button  and if there was 200 more buttons there i would have pressed them  for you
                            =================

                            and other guys
                            Geek-9pm ---Sidewinder---Squashman----Salmon Trout
                            thank you  all too you  tried to  teach  me a lot :)


                            mioo_sara

                              Topic Starter


                              Intermediate

                              Re: copy all files and folders from current folder
                              « Reply #28 on: April 08, 2012, 12:51:15 PM »
                                  i have a little problem  i forgot to  ask  how should this batch  file create a folder in  destination  and rename it to  current folder's name before copying files and folders from current directory  to  it
                                  in  another language
                                  1-first create a folder in destination  d:\backup\ and rename it to  current folder's name= example johns(where my  files and folders located now)
                                  2- now copy  files and folders from current directory(johns)  fo  d:\backup\ new destination  folder (example=johns)
                                  thanks :)


                              mioo_sara

                                Topic Starter


                                Intermediate

                                Re: copy all files and folders from current folder
                                « Reply #29 on: April 10, 2012, 01:54:09 AM »
                                thanks  its done above post has been  solved thanks dear friends ;)