locked
script batch copy files RRS feed

  • Question

  • I need a script (batch) that I copy the files in one folder. Let me explain.
    FOLDER01
          
    FOLDER001
                  
    aa.txt
                  
    bb.txt
          
    FOLDER002
                  
    aa.txt
                  
    cc.txt

    FOLDER02
                  
    aa.txt
                  
    bb.txt
                  
    cc.txt

    If there is redone, I need that file is renowned aa_folder01.txt

    Help me?
    Monday, September 27, 2010 6:45 PM

Answers

  • I believe this batch file does what you want from the command prompt ...

     @echo off
      pushd "d:\someplace\FOLDER01"
      set dest=d:\someplace\FOLDER02
      for /d %%F in (*) do (
        for %%a in ("%%F\*.*") do (
          if not exist "%dest%\%%~nxa" (
            copy "%%a" "%dest%\%%~nxa"
          ) else (
            copy "%%a" "%dest%\%%~na_%%~nF%%~xa"
          )
        )
      )
      popd

    Replace the d:\someplace part with the appropriate location or remove that part and start the batch procedure in the folder just above FOLDER01.


    Tom Lavedas
    Monday, September 27, 2010 8:52 PM

All replies

  • Sorry, your post is unclear. Can you expand it and/or rephrase your question?
    Monday, September 27, 2010 7:09 PM
  • Sorry.

    I need a script that I copy the files included in the FOLDER01 and subfolders but without  FOLDER01 structure


    FOLDER01
          
    FOLDER001
                  
    aa.txt
                  
    bb.txt
          
    FOLDER002
                  
    aa.txt
                  
    cc.txt

    FOLDER02
                  
    aa.txt
                  
    bb.txt
                  
    cc.txt

    If there are repeated, I need that file is renowned aa_folder01.txt

    Monday, September 27, 2010 7:22 PM
  • I assume that
    If there are repeated, I need that file is renowned aa_folder01.txt
    means
    If a file already exists in the target folder then it should be renamed to aa_folder01.txt

    Unfortunately this interpretation adds little to clarify your job specification. In view of the linguistic problem we have I recommend you repost your question in a forum that caters for your own language. Alternatively you could explain the problem to an English speaker and have it translated to English.

    Monday, September 27, 2010 8:14 PM
  • Ok, forget the last option. I can copy files and to replace the duplicates?
    Monday, September 27, 2010 8:26 PM
  • Yes - use xcopy.exe with the /Y switch. Type xcopy /? at the Command Prompt to see all available switches.
    Monday, September 27, 2010 8:40 PM
  • I believe this batch file does what you want from the command prompt ...

     @echo off
      pushd "d:\someplace\FOLDER01"
      set dest=d:\someplace\FOLDER02
      for /d %%F in (*) do (
        for %%a in ("%%F\*.*") do (
          if not exist "%dest%\%%~nxa" (
            copy "%%a" "%dest%\%%~nxa"
          ) else (
            copy "%%a" "%dest%\%%~na_%%~nF%%~xa"
          )
        )
      )
      popd

    Replace the d:\someplace part with the appropriate location or remove that part and start the batch procedure in the folder just above FOLDER01.


    Tom Lavedas
    Monday, September 27, 2010 8:52 PM
  • Ok, forget the last option. I can copy files and to replace the duplicates?
    Monday, September 27, 2010 8:54 PM