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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:04:22+00:00 2026-06-06T10:04:22+00:00

I have a working file rename java tool, now I want to add an

  • 0

I have a working file rename java tool, now I want to add an if condition to run a commandline command if I checked a box as part of the rename process on each file it renames.

I will be changing the dos code later, but its a sample I found that works. Part of my problem is my filerename is its own class, so I will also need to figure out how to combine this class or reference the dos command somehow from my main rename class.

update

I updated the code with the changes from the answer, but the commandline command does not work and it crashes java with no error. The command does work from cmd line.

import java.io.IOException;
import java.io.InputStream;

public class doscommandrun {
     public static void run() {  
         final String dosCommand = "cmd converter.exe file.doc -android -o file.txt";
            try {
                final Process process = Runtime.getRuntime().exec(
                        dosCommand + " ");
                final InputStream in = process.getInputStream();
                int ch;
                    while((ch = in.read()) != -1) {
                        System.out.print((char)ch);
                    }
                    } catch (IOException e) {
                        e.printStackTrace();
            }
        }
    }

enter code hereFile rename code:

private void renameFile(){

    boolean operationResult = false;
    boolean overallResult = true;
    int failCount = 0;

    /* the operation of this part is ensured by the chooseDirectory()
     * WE get the list of files in the directory
     * get the conditions set by users
     * and perform the file rename operation.
     */

    //Let's get all the information from user
    String[] fileList = directory.list();  //the list of files in the directory
    String Prefix = txtPrefix.getText();
    String Rename = txtRename.getText();
    String Suffix = txtSuffix.getText();
    String digits = (String) cboSequence.getSelectedItem();
    int StartingNum;
    String generatedSequence;
    File oldFile;

    //let's call the output frame
    if(cbxOutput.isSelected() && OUTPUT_ON == false){
        buildOutput();
        OUTPUT_ON = true;
    }




    //display the list of files and readability of each file
    for(int i = 0; i < fileList.length; i++){   
        oldFile = new File(directory.getPath()+"/"+ fileList[i]);
        String readability = fileList[i] +" - readable?: "+oldFile.canRead();
        System.out.println(readability);

        if(OUTPUT_ON)
            txaOutput.append("\n"+readability);
    }

    for(int i = 0; i < fileList.length; i++){

        /* get the file extension that we need, and form a new name, 
         * we would check if the Ignore File Extension is selected
         */
        oldFile = new File(directory.getPath()+"/"+ fileList[i]);

        String fileExtension;

        if(cbxIgnoreExtension.isSelected() == true ){
            fileExtension = "";
        }
        else
            fileExtension = getFileExtension(fileList[i]);

        //this part get the original filename       
        String fileName = getFileName(fileList[i]);



        String inputInfo = "The input filename->"+ fileList[i] + "\nfile name->" + fileName + "\nextension->" + fileExtension;   
        System.out.println(inputInfo);

        if(OUTPUT_ON)
            txaOutput.append("\n"+inputInfo);



        /* generate sequence for the Name
         *if the digits selection is NONE, we ignore it
         */
        if(digits.equals("None") == true){
            generatedSequence = "";
        }
        else{
            StartingNum = Integer.parseInt(txtSequence.getText());
            generatedSequence = nameSequence(StartingNum + i, digits);
        }




        //this is affected by the RenameOption, if Rename has something then only we RENAME
        if(cbxRename.isSelected() == true){
            fileName = Rename + generatedSequence;   //the fileName will change.
        }
        else{
            //if Rename has nothing, but the txtSequence has some Value, we take it to the naming too
            fileName = fileName.substring(0,4)+ generatedSequence;
            if(cbxAndroid.isSelected() == true ){
                doscommandrun.run();
                }



        //the New File Name
        String newFileName = Prefix + fileName.substring(0,4) + Suffix + fileExtension;
        String tentativeName = "new Filename will be ->"+newFileName+"\n";
        System.out.println(tentativeName);

        if(OUTPUT_ON)
            txaOutput.append("\n"+tentativeName);




        // ! Perform the file rename, if the Experimental Mode is not selected
        if(cbxExperiment.isSelected() == false){

            operationResult = oldFile.renameTo(new File(directory.getPath()+"/"+newFileName));
            String renameResult = "\t*Rename successfully?: " + operationResult+"\n\n";
            System.out.println(renameResult);
                if(operationResult == false)
                    failCount++;

                if(OUTPUT_ON)
                    txaOutput.append("\n"+renameResult);

            //make up the overall result
            overallResult = (operationResult && overallResult);
        }

    }

    if(cbxExperiment.isSelected() == false){
        System.out.println("Overall Result: "+overallResult);
        if(overallResult)
            JOptionPane.showMessageDialog(null, "All files renamed successfully!");
        else
            JOptionPane.showMessageDialog(null, "File renamed with "+ failCount+ " failure(s)");
    }//end if
    }

}//end renameFile
  • 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-06T10:04:24+00:00Added an answer on June 6, 2026 at 10:04 am

    I add /c after the cmd in my renametool class

    I am still having issues but wither a different problem.

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

Sidebar

Related Questions

I have checked a file temp.pl but now I want to change into temp
I have a working Java app that can find the most recently created file
I want to rename the app I'm working on. I have changed the Bundle
I have been working on designing a file server that could take the load
I have been working with Fortran for years, but the file I/O is still
I have recently been working on implementing an ajax based file uploader for my
I have a CSV file that I'm working with, and all the fields are
I am working on project -online file management where we have to tore file
I am working with a log file and I have a method which is
I have a large program that is working other then one .h file that

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.