Announcement

Collapse
No announcement yet.

Copy files Using a List

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy files Using a List

    I need to create a batch file to copy files that are reference in a Text file. I dont want to copy anything other than what is in the text file. I need it re-create the directory structure in the destination.

    Here is what I have so far (that is not working).

    for /F "delims=*" %%i in (C:\lists.txt) do echo F| xcopy /S /I /Y c:\folder\%%i "%%i"c:\bkup\

    I have tried this as well but no luck

    for /F %%a in (C:\lists.txt) do echo xcopy *.pdf /S /I /Y c:\bkup

  • #2
    Re: Copy files Using a List

    Originally posted by 100mbs View Post
    I need to create a batch file to copy files that are reference in a Text file. I dont want to copy anything other than what is in the text file. I need it re-create the directory structure in the destination.

    Here is what I have so far (that is not working).

    for /F "delims=*" %%i in (C:\lists.txt) do echo F| xcopy /S /I /Y c:\folder\%%i "%%i"c:\bkup\

    I have tried this as well but no luck

    for /F %%a in (C:\lists.txt) do echo xcopy *.pdf /S /I /Y c:\bkup
    When the lists.txt file contains just a relative path for the files to copy, maybe something like,
    Code:
    @echo off
    
    Set "SourceFolder=c:\folder"
    Set "DestinationFolder=c:\bkup"
    
    pushD "%DestinationFolder%" ||goto:EOF
    
    for /F "usebackq tokens=*" %%i in (
      "C:\lists.txt"
      ) do xcopy /S /I /Y "%SourceFolder%\%%~i" "%%~dpi"
    
    popD

    OR, when the lists.txt file contains the full path to the source and/or a relative path for the files to copy,
    Code:
    @echo off
    
    Set "SourceFolder=c:\folder"
    Set "DestinationFolder=c:\bkup"
    
    pushD "%DestinationFolder%" ||goto:EOF
    
    for /F "usebackq tokens=*" %%i in (
      "C:\lists.txt"
      ) do call:bak %%~i
    
    popD
    
    goto:EOF
    :bak
    Set "relativePath=%*"
    call Set "relativePath=%%relativePath:%SourceFolder%\=%%"
    
    for /f "tokens=*" %%* in (
      'echo.%relativePath%'
      ) do xcopy /S /I /Y "%SourceFolder%\%relativePath%" "%%~dp*"
    exit /b 0

    /Rems
    Last edited by Rems; 21st April 2011, 11:37.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X