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

Author Topic: xcopy for specific files and their folders  (Read 8676 times)

0 Members and 1 Guest are viewing this topic.

garv

    Topic Starter


    Greenhorn

    xcopy for specific files and their folders
    « on: May 26, 2009, 12:59:44 PM »
    Greetings.

    I have a situation for which I'm attempting to use xcopy (or xxcopy) to resolve, but have not yet had success with it. What I need to do is copy a series of specific files (if I am successful, this it will be 100's to 1,000's of files at a time) from different folders to a specified location. What I also need is for the directory structure (1 or 2 folders deep) to be replicated as well.

    I have found instructions on using .xcf files for composing the list of files, but as of this point of time, I have not been successful in what I've defined above.

    Any insights on the proper syntax, or even the ability/inability to do this with xcopy, or other means would be greatly appreciated. Thank you in advance.

    Reno



      Hopeful
    • Thanked: 32
      Re: xcopy for specific files and their folders
      « Reply #1 on: May 27, 2009, 12:13:09 AM »
      have you look at the help file

      Code: [Select]
      D:\batch>xcopy/?
      Copies files and directory trees.

      XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                                 [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                                 [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                                 [/EXCLUDE:file1[+file2][+file3]...]

        source       Specifies the file(s) to copy.
        destination  Specifies the location and/or name of new files.
        /E           Copies directories and subdirectories, including empty ones.
                     Same as /S /E. May be used to modify /T.
        /I           If destination does not exist and copying more than one file,
                     assumes that destination must be a directory.

      garv

        Topic Starter


        Greenhorn

        Re: xcopy for specific files and their folders
        « Reply #2 on: May 27, 2009, 06:27:49 AM »
        Reno,

        Thanks. And yes I've been looking through many of the posts online and doing my best to decipher all the switches. What you made reference to sounds correct, but in my experience with attempting to use them, does not quite accomplish what I'm after.

        For example: If I have a folder named "folder1" that contains files "a","b","c" and "d", I may only have the need for file "b". I'm currently able to copy file "b" out of the folder (and have used various switches) and to a different directory, but in doing so it does not create "folder1" and place file "b" inside of it, it merely copies file "b" to the folder I specify.

        The reason I'm attempting this is a work around to a hyperlinking issue with g.i.s.. The database I'm working with has over 14,000 records in about 250 different folders and I need to maintain the directory structure for the hyperlinking to work.

        Reno



          Hopeful
        • Thanked: 32
          Re: xcopy for specific files and their folders
          « Reply #3 on: May 27, 2009, 07:33:13 AM »
          type:
          dir/b/s file_b.txt somemorefile.txt fileiwanttocopy.txt

          does the above output match your requirement for the files to copy?
          and how many is the "b" condition out of the many files of a-z?

          ALAN_BR



            Hopeful

            Thanked: 5
            • Computer: Specs
            • Experience: Experienced
            • OS: Windows 7
            Re: xcopy for specific files and their folders
            « Reply #4 on: May 27, 2009, 08:06:46 AM »
            Hi

            The problem is not yet clear to me.

            Does each of the 250 folders have 56 required files,
            and are the identically same file names required in each of the 250 folders ?

            If so then something like this may work :-
            Code: [Select]
            FOR %%A IN (PATH1 PATH2 ... PATH249 PATH250) DO (
              FOR %%B IN (FILE1 ... FILE55 FILE56) DO (
                XCOPY %%A\%%B NEW\%%A\%%B
              )
            )

            If not then you probably have to list as 14,0000 items the complete path and file that is required

            Regards
            Alan

            garv

              Topic Starter


              Greenhorn

              Re: xcopy for specific files and their folders
              « Reply #5 on: May 27, 2009, 04:21:24 PM »
              Thank you for your posts. I won't be able to experiment with your suggestions until sometime tomorrow (5/28).

              In an attempt to clarify: no the 250+ folders do not have the same required files or identically named files.

              I need this to work, so when I'm required to subset data, I can copy out ONLY the files (in this case image files) for the subset that I'm performing. It will change with every subset that I do.

              After I perform a subset, I will be able to pull out all the paths of the files I need from the database, format them as needed and paste them into a txt file, thus my attempts at using the .xcf files with xcopy.

              If you are familiar with zip utilities, you often have the option when creating the zip archive to save the directory structure in which the files you are compressing reside. In this way, when you decompress the zip archive, a directory structure is created so the files you added to archive reside within the same directory structure from which they were copied. This is the effect that I'm after.

              hope this helps. thanks again.


              Reno



                Hopeful
              • Thanked: 32
                Re: xcopy for specific files and their folders
                « Reply #6 on: May 27, 2009, 10:30:24 PM »
                After I perform a subset, I will be able to pull out all the paths of the files I need from the database, format them as needed and paste them into a txt file, thus my attempts at using the .xcf files with xcopy.
                then consider it done because you already have the list of file path in a file. now need a little bit more information:
                1. is this file path is full-path-name or relative-path-name?
                2. would you mind to post couple of lines from the xcf file.

                i am thinking to do it in a simple for loop and light-weight copy function.

                garv

                  Topic Starter


                  Greenhorn

                  Re: xcopy for specific files and their folders
                  « Reply #7 on: May 28, 2009, 09:41:47 AM »
                  Thank you Reno. You give me hope. I just spent another couple hours looking for solutions and it may involve setting parameters in a batch file, but again, I'm not fully understanding what I'm seeing.

                  So far, I've been using full-path-names, as that is how I've been able to successfully copy files across the network.

                  Below is a sampling of the files I need to copy and create the directory structure for. As you can see, there are a variety of directories and only a few files from each.

                  "T:\! Field_Verification_Data\BW\Big Walnut27\50.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\48.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\87.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\58.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\62.jpg" "T:\! Field_Verification_Data\BW\Big Walnut101\90.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\70.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\73.jpg" "T:\! Field_Verification_Data\BW\Big Walnut101\70.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\80.jpg" "T:\! Field_Verification_Data\BW\Big Walnut100\55.jpg" "T:\! Field_Verification_Data\BW\Big Walnut100\38.jpg" "T:\! Field_Verification_Data\BW\Big Walnut56\68.jpg"  c:\pics /oAlog/h/c/e/r/y

                  I don't mind concatenating what is needed to each entry to allow this to work, so I look forward to your suggestions.

                  f.y.i. I'm including a bit of coding I found that may be something to consider as well, but I'll await your suggestions.

                  @echo off
                  for  /F  "tokens=*"  %%*  in (c:\Files.txt)  do  xcopy /y /c /d /h "%%*"
                  d:\Target\

                  Reno



                    Hopeful
                  • Thanked: 32
                    Re: xcopy for specific files and their folders
                    « Reply #8 on: May 28, 2009, 09:56:20 AM »
                    "T:\! Field_Verification_Data\BW\Big Walnut27\50.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\48.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\87.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\58.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\62.jpg" "T:\! Field_Verification_Data\BW\Big Walnut101\90.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\70.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\73.jpg" "T:\! Field_Verification_Data\BW\Big Walnut101\70.jpg" "T:\! Field_Verification_Data\BW\Big Walnut27\80.jpg" "T:\! Field_Verification_Data\BW\Big Walnut100\55.jpg" "T:\! Field_Verification_Data\BW\Big Walnut100\38.jpg" "T:\! Field_Verification_Data\BW\Big Walnut56\68.jpg"  c:\pics /oAlog/h/c/e/r/y
                    before i write something up, need to confirm a few things:
                    is it no line-break between each entry? or the formatting is loss due to copy&paste from unix system maybe??
                    what is this last line mean -  c:\pics /oAlog/h/c/e/r/y?
                    there is a limit in cmd a certain number of characters in a variable.

                    if you able to format the file like this:
                    Code: [Select]
                    "T:\! Field_Verification_Data\BW\Big Walnut27\50.jpg"
                    "T:\! Field_Verification_Data\BW\Big Walnut27\48.jpg"
                    "T:\! Field_Verification_Data\BW\Big Walnut27\87.jpg"
                    "T:\! Field_Verification_Data\BW\Big Walnut27\58.jpg"
                    "T:\! Field_Verification_Data\BW\Big Walnut27\62.jpg"
                    then a batch code would be possible, otherwise i need to do it in another scripting language, such as vbscript
                    « Last Edit: May 28, 2009, 10:06:51 AM by Reno »

                    garv

                      Topic Starter


                      Greenhorn

                      Re: xcopy for specific files and their folders
                      « Reply #9 on: May 28, 2009, 10:17:24 AM »
                      Correct, what I pasted has no line-breaks between entries, however if I need line breaks (or commas, tabs etc.), I can make it that way.

                      The last line is what I was using as the destination directory (this can be anything), and the remainder were xcopy switches including the creation of a log file for errors, which I have found helpful in the past.

                      Reno



                        Hopeful
                      • Thanked: 32
                        Re: xcopy for specific files and their folders
                        « Reply #10 on: May 28, 2009, 10:51:37 AM »
                        for this text format with line break, support unlimited number of entry:
                        destination directory is at the top for performance sake, if you put the destination directory on the last line, it will take a long time for large list
                        Code: [Select]
                        c:\pics
                        "T:\! Field_Verification_Data\BW\Big Walnut27\50.jpg"
                        "T:\! Field_Verification_Data\BW\Big Walnut27\48.jpg"
                        "T:\! Field_Verification_Data\BW\Big Walnut27\87.jpg"
                        "T:\! Field_Verification_Data\BW\Big Walnut27\58.jpg"
                        "T:\! Field_Verification_Data\BW\Big Walnut27\62.jpg"
                        the batch code:
                        Code: [Select]
                        @echo off & setlocal

                        set /p dest=<test.txt
                        if %dest:~-1%.==\. set dest=%dest:~0,-1%

                        for /f "skip=1 tokens=*" %%a in (test.txt) do (
                        if not exist "%dest%%%~pa" md "%dest%%%~pa" && echo created "%dest%%%~pa"
                        echo copying "%%~a"
                        copy "%%~a" "%dest%%%~pa"
                        )

                        garv

                          Topic Starter


                          Greenhorn

                          Re: xcopy for specific files and their folders
                          « Reply #11 on: May 28, 2009, 11:38:21 AM »
                          Reno,

                          Fantastic. I tested what you posted and it worked, then I chose a more complex set of paths and files and it worked perfectly. That is exactly what I'm in need of. Rest assured it will be put to good use.

                          If it is ok with you I will make this available to other people that have had the same issue that I was dealing with; there are many. If you'd like to receive some feedback or credits for this I know a place we can probably post it. Let me know your thoughts.

                          In the mean time I will spend some more time deciphering what you created and test it in some different ways.

                          Once again. Fantastic. Thank You.

                          Reno



                            Hopeful
                          • Thanked: 32
                            Re: xcopy for specific files and their folders
                            « Reply #12 on: May 29, 2009, 01:18:45 AM »
                            glad it works well.

                            feel free to modify and give it to your friends, just dont put my name on it, i'll be ashamed if my name tagged somewhere for such a simple script.

                            if the simple script help you out somehow, you only need to click "thanks at post #11". that's more than enough  :)
                            btw, click once only, i don't like cheating  :P

                            garv

                              Topic Starter


                              Greenhorn

                              Re: xcopy for specific files and their folders
                              « Reply #13 on: May 29, 2009, 05:50:53 AM »
                              Reno,

                              I clicked the thank you button 'once' for you yesterday right after I tested the script. If I can do what I'd like to with the script I will give you an update, it really could help a lot of people. Have a good weekend. - josh

                              ElfMajesty



                                Starter

                                Re: xcopy for specific files and their folders
                                « Reply #14 on: June 30, 2009, 07:28:17 AM »
                                Reno,

                                I'd like to join in on the thank you's here!!  In researching the very issue and need over the past two days (and many experiments later), I came across this thread and was able to implement your .bat in the exact manner I needed.   :)

                                Best regards,

                                L. Burr