Discussions

Copy only select files from multiple sub-directories using xcopy

+
0 Votes
Locked

Copy only select files from multiple sub-directories using xcopy

sporzondek
Is there a way to copy only select files that reside in sub-directories using the xcopy command in a batch file? Example: text file has list of 2500+images that are in multiple sub-directories under one main directory. The entire library has over 500,000 images so it is imperative to only copy what is needed. Is there a way to do this in Windows using xcopy in a batch file?
  • +
    0 Votes
    seanferd

    but you'd have to define which files you actually want, which, in the end, may involve listing each file individually.

    I'm not sure I see a way to pipe a list from a text file directly to the xcopy command. You might have to write a batch file to do this using For...In...Do...

    Ah, here's an example:
    http://www.itnewsgroups.net/group/microsoft.public.windows.server.general/topic34064.aspx

    More:
    http://www.computing.net/answers/programming/batch-copy-files-using-txt-list/18010.html

    General:
    http://home.att.net/~gobruen/progs/dos_batch/dos_batch.html#batch_util

    On the other hand, if you had a text file of all the files in the directories that you <i>don't</i> want to copy, the xcopy /exclude would work well.

    I've had a look at the utility xxcopy (which is a nice xcopy replacement), but it lacks this functionality as well.

    Good luck.

    P.S.
    If these files would tend to group themselves in the Explorer GUI (choose Details View) by sorting by date, name, etc. by clicking on the detail columns, then just copying from Explorer may be faster

    +
    0 Votes
    sporzondek

    I have the image id numbers in a text file. I just need to extract them and copy to a repository folder. (Image ids are database references, so there is no filepath information that is attached. I have to include that in the text file, but do not know exactly which sub folder each image is in.) from my research findings, I do not see a way to do this easy in windows. I basically need to find a way to searh directories for a specific id, find that id, then copy to destination folder. Any suggestions?

    +
    0 Votes
    NickNielsen Moderator

    The command
    "dir drive\path\filename.ext /s"
    will list all the files in the specified directory and all subdirectories.

    To send the output to a file, use the redirect symbol ">".

    Use the /b switch to save only the filename.ext

    Your command would look something like:

    [pre]dir d:\path\file*.ext /s /b > destfile.ext[/pre]

  • +
    0 Votes
    seanferd

    but you'd have to define which files you actually want, which, in the end, may involve listing each file individually.

    I'm not sure I see a way to pipe a list from a text file directly to the xcopy command. You might have to write a batch file to do this using For...In...Do...

    Ah, here's an example:
    http://www.itnewsgroups.net/group/microsoft.public.windows.server.general/topic34064.aspx

    More:
    http://www.computing.net/answers/programming/batch-copy-files-using-txt-list/18010.html

    General:
    http://home.att.net/~gobruen/progs/dos_batch/dos_batch.html#batch_util

    On the other hand, if you had a text file of all the files in the directories that you <i>don't</i> want to copy, the xcopy /exclude would work well.

    I've had a look at the utility xxcopy (which is a nice xcopy replacement), but it lacks this functionality as well.

    Good luck.

    P.S.
    If these files would tend to group themselves in the Explorer GUI (choose Details View) by sorting by date, name, etc. by clicking on the detail columns, then just copying from Explorer may be faster

    +
    0 Votes
    sporzondek

    I have the image id numbers in a text file. I just need to extract them and copy to a repository folder. (Image ids are database references, so there is no filepath information that is attached. I have to include that in the text file, but do not know exactly which sub folder each image is in.) from my research findings, I do not see a way to do this easy in windows. I basically need to find a way to searh directories for a specific id, find that id, then copy to destination folder. Any suggestions?

    +
    0 Votes
    NickNielsen Moderator

    The command
    "dir drive\path\filename.ext /s"
    will list all the files in the specified directory and all subdirectories.

    To send the output to a file, use the redirect symbol ">".

    Use the /b switch to save only the filename.ext

    Your command would look something like:

    [pre]dir d:\path\file*.ext /s /b > destfile.ext[/pre]