Announcement

Collapse
No announcement yet.

Help with script or xcopy command

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

  • Help with script or xcopy command

    Hi everybody, can anyone help me? I need to copy all the files in several locations to a single location. Example:

    C:\images\folder1\a.jpg
    C:\images\folder2\b.jpg
    C:\images\folder3\1\c.jpg
    C:\images\folder4\1\2\d.jpg

    I need the images in a single directory, like this:

    C:\all\a.jpg
    C:\all\b.jpg
    C:\all\c.jpg
    C:\all\d.jpg

    How can I do it? Can I do it using xcopy / copy or do I need a batch file?

    Thanks a lot
    Last edited by Lamberth; 11th July 2008, 12:06.

  • #2
    Re: Help with script or xcopy command

    Originally posted by Lamberth View Post
    Hi everybody, can anyone help me? I need to copy all the files in several locations to a single location.

    How can I do it? Can I do it using xcopy / copy or do I need a batch file?
    You can use a one-liner command line:
    Code:
    cmd /c For /F "tokens=* delims=" %* in ('Dir /b /s "C:\images\*.jpg" 2^>nul') Do @ %WinDir%\system32\xcopy.exe /O /D /Y "%*" "C:\all\"
    Doing it by batch, it would look like:
    Code:
    @echo off
    
    Set "sourcefiles=C:\images\*.jpg" (search also in subdirectories)
    Set "destinationfolder=C:\all"
    
    If Not exist "%destinationfolder%" (MkDir "%destinationfolder%")
    
    For /F "tokens=* delims=" %%* in (
       'Dir /b /s "%sourcefiles%" 2^>nul'
       ) Do echo.%%~nx* &(
       %WinDir%\system32\xcopy.exe /O /D /Q /Y "%%*" "%destinationfolder%\" >nul
    )
    \Rems
    Last edited by Rems; 1st September 2008, 17:23.

    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


    • #3
      Re: Help with script or xcopy command

      There's something wrong here:

      @echo off

      Set "sourcefiles=C:\images\*.jpg" (search also in subdirectories)
      Set "destinationfolder=C:\all\"

      If Not exist "%destinationfolder%" (MkDir "%destinationfolder%")

      For /F "tokens=* delims=" %%* in (
      'Dir /b /s "%sourcefiles%" 2^>nul'
      ) Do echo.%%~nx* &(
      %WinDir%\system32\xcopy.exe /O /D /Q /Y "%%*" "%destinationfolder%\" >nul
      )





      It says error creating file, can't create an existing file. Can't create
      directory C:\all

      Can you check again what is wrong please?
      Thanks a lot

      Comment


      • #4
        Re: Help with script or xcopy command

        never mind, problem solved!

        thanks a lot

        Comment


        • #5
          Re: Help with script or xcopy command

          Hi Lamberth,

          Thanks for the reply.

          I have corrected the line:
          from: Set "destinationfolder=C:\all\"
          __to: Set "destinationfolder=C:\all"

          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