Share via

DOS Copy Command

Fred Zuckerman 21 Reputation points
2021-04-24T04:39:50.427+00:00

I want to copy all files in a directory that end in "*1.zip" to the same name but ending in "*7.zip"

I tried (but it didn't work)

copy c:\users\fred\*1.zip c:\users\fred\*7.zip

Suggestions?
Thanks

Windows development | Windows API - Win32

4 answers

Sort by: Most helpful
  1. Fred Zuckerman 21 Reputation points
    2021-04-28T02:08:28.157+00:00

    I hope to experiment more with these suggestions tonight or tomorrow. I'll post my results thereafter. Thank you. Fred

    Was this answer helpful?

    0 comments No comments

  2. Viorel 127K Reputation points
    2021-04-25T20:45:10.637+00:00

    Try executing a .BAT file containing something like this:

    @echo off
    for %%f in (c:\users\fred\*1.zip) do ( call :sub "%%f" )
    goto :end
    :sub
    set p=%~1
    set p=%p:~0,-5%
    set p=%p%7.zip
    echo copy %1 "%p%"
    :end
    

    It displays the generated "copy" commands. Remove "echo" to copy the files effectively.

    Was this answer helpful?

    0 comments No comments

  3. WayneAKing 4,936 Reputation points
    2021-04-24T22:30:31.197+00:00

    [repost as my first try disappeared]

    Unfortunately, the filenames are various lengths

    If all else fails, you could of course use a rather
    "cludgy" approach such as this in a bat file:

    copy c:\users\fred\?1.zip c:\users\fred\?7*
    copy c:\users\fred\??1.zip c:\users\fred\??7*
    copy c:\users\fred\???1.zip c:\users\fred\???7*
    copy c:\users\fred\????1.zip c:\users\fred\????7*
    copy c:\users\fred\?????1.zip c:\users\fred\?????7*
    copy c:\users\fred\??????1.zip c:\users\fred\??????7*
    etc.

    • Wayne

    Was this answer helpful?

    0 comments No comments

  4. WayneAKing 4,936 Reputation points
    2021-04-24T19:38:18.52+00:00

    Do all of the files to be copied have the same length
    file names? If so, you can do this (example assumes
    a five-character name preceding the 1):

    copy ?????1.zip ?????7*

    copy c:\users\fred\?????1.zip c:\users\fred\?????7*

    • Wayne

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.