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 6864953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:58:45+00:00 2026-05-27T02:58:45+00:00

I need to copy a directory form one source form multiple destination . For

  • 0

I need to copy a directory form one source form multiple destination. For example, i copied a file from my C: drive and paste it into many external drives like E:,F:,G:…etc. For this process i used the following code,

set src=%~1

:Loop
    shift
    set dest=%~1
    if "%dest%"=="" goto :EOF
    xcopy "%src%" "%dest%" /E
goto Loop

i saved this code snippet as .bat in system32 folder. Then i use this command as

C:\Windows\System32>mcopy C:\Users\FSSD\Desktop\Screenshot E: F:

i executed this command in my command prompt it executed successfully.

Then i tried to implement this command in my java application.

My java code is,

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class MultipleCopy{

    public static void main(String args[]) {

        String exe_Cmd = "c:/Windows/System32/mcopy C:/Users/FSSD/Desktop/Screenshot E: F:";
        Runtime r = Runtime.getRuntime();
        ProcessBuilder p = new ProcessBuilder(new String[] { "cmd.exe", "/C",
                exe_Cmd });
        Process pro;
        try {
            pro = p.start();
            InputStream is = pro.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.err.println("IO Exception" + e.getMessage());
        }

    }
}

it was executed without any errors but the files won’t copied.

My eclipse IDE’s console’s output is:

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>set src=C:/Users/FSSD/Desktop/Screenshot 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>shift

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>set dest=E: 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>if "E:" == "" goto :EOF 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>xcopy "C:/Users/FSSD/Desktop/Screenshot" "E:" /E 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>goto Loop 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>shift

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>set dest=F: 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>if "F:" == "" goto :EOF 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>xcopy "C:/Users/FSSD/Desktop/Screenshot" "F:" /E 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>goto Loop 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>shift

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>set dest= 

C:\Users\FSSD\IndigoWorkSpace\Multi_Copy>if "" == "" goto :EOF 

In this, what is my mistake, how can i get the exact output. Reply me as soon as possible. Thanks in advance…!

  • 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-05-27T02:58:46+00:00Added an answer on May 27, 2026 at 2:58 am

    Parameters to ProcessBuilder may not contain spaces, instead of

    String exe_Cmd = "c:/Windows/System32/mcopy C:/Users/FSSD/Desktop/Screenshot E: F:";
    

    you need

    String[] pars = {"cmd.exe", "/C","c:/Windows/System32/mcopy","C:/Users/FSSD/Desktop/Screenshot","E:","F:"};
    Runtime r = Runtime.getRuntime();
    ProcessBuilder p = new ProcessBuilder(pars);
    

    But I still would rather use a Java solution, like I suggested in the comments already 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to copy a jar file from one directory to another when my
I would like to copy the file from source to destination directory. I heard
I need to copy multiple files from a directory using a textfile that doesnt
I need to copy the newest file in a directory to a new location.
I need to copy all *.exe files in some directory to other virtual drive
I need to copy files in one directory to another directory where the lastwritetime
I need to copy about 40 databases from one server to another. The new
I need to copy several tables from one DB to another in SQL Server
As part of a larger batch script, I need to copy a directory from
I need to copy a few files to another directory. The source structure is

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.