Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:02:29+00:00 2026-06-15T08:02:29+00:00

I want to copy specific file from pc to usb my code : xcopy

  • 0

I want to copy specific file from pc to usb

my code :

  xcopy /H /Y /C /R "C:\image1.jpeg" "G:\backup\image.jpeg"

i want to do following :
if G:\backup\image1.jpeg exist, copy image.jpeg as image2.jpeg (or as another name),

if image2.jpeg exist, copy as image3.jpeg and ect..

Is it possible to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:02:30+00:00Added an answer on June 15, 2026 at 8:02 am

    I’m going to assume your source name is “image.jpeg” and your destination has the appended suffix.

    I recommend putting a dot before the appended suffix to make it clear where the original name ends and the suffix begins. Your original name could already have a number at the end.

    Here is a crude but very effective brute force method that supports up to 100 copies. Obviously the upper limit can easily be increased.

    call :backup "c:\image.jpeg"
    exit /b
    
    :backup
    for /l %%N in (1 1 100) do (
      if not exist "G:\backup\%~n1.%%N.%~x1" (
        echo F|xcopy %1 "G:\backup\%~n1.%%N.%~x1" >nul
      )
      exit /b
    )
    

    But there is a potential problem. Suppose image.1.txt and image.2.txt already exist, but then you delete image.1.txt. The next time you backup it will re-create image.1.txt and then you might think that image.2.txt is the most recent backup.

    The following can be used to always create a new backup with the number suffix 1 greater than the largest existing suffix, even if there are wholes in the numbers.

    @echo off
    call :backup "c:\image.jpeg"
    exit /b
    
    :backup
    setlocal disableDelayedExpansion
    set /a n=0
    for /f "eol=: delims=" %%A in (
      'dir /b "g:\backup\%~n1.*%~x1"^|findstr /rec:"\.[0-9][0-9]*\%~x1"'
    ) do for %%B in ("%%~nA") do (
      setlocal enableDelayedExpansion
      set "n2=%%~xB"
      set "n2=!n2:~1!"
        if !n2! gtr !n! (
        for %%N in (!n2!) do (
          endlocal
          set "n=%%N"
        )
      ) else endlocal
    )
    set /a n+=1
    echo F|xcopy %1 "g:\backup\%~n1.%n%%~x1" >nul
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want grant user rights to copy a specific file from a remote server
I want to copy multiple files from a specific directory once I am in
i want copy pdf file from application path(/data/data/package name) to sdcard.for that i have
I want to copy a selection of lines from a file to another file
I want to copy a xml file from one remote box to a bunch
I want to copy specific file done last changes in Oct 16-17,file type is
I have a template file I want to copy and then edit from a
I want to copy few files into an existing zip file using ANT script.
I want to copy directories and their subdirectories from C: to D: with same
I want to copy the newest file that is on a mapped network directory.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.