Home Answers Viewqa Java-Beginners Renaming multiple files

 
 


mydocumentsandmails
Renaming multiple files
2 Answer(s)      a year ago
Posted in : Java Beginners

Hi,

I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. ....

Now I wanted to rename these files as: 1RohitBBorse.mp4, 2RohitBBorse.mp4, 3_RohitBBorse.mp4, ....

Please suggest me through java program how I can fulfill this requirement. Instead of going one by one I want to do this at one shot through Java program.

Thanks in advance. :)

  • Rohit Borse
View Answers

May 2, 2012 at 4:41 PM


import java.io.*;
class RenameFiles 
{
    public static String getFileNameWithoutExtension(String fileName) {
          File file = new File(fileName);
          int index = file.getName().lastIndexOf('.');
          if (index>0&& index <= file.getName().length() - 2 ) {
            System.out.println("Filename without Extension: "+file.getName().substring(0, index));
          }  
          return "";
    } 
    public static void main(String[] args){
        String files[]={"c:/1Angelrose0705$.jpg","c:/2Angelrose0705$.jpg","c:/3Angelrose0705$.jpg","c:/4Angelrose0705$.jpg"};
        File oldfile[]=new File[files.length];
        String st[]=new String[files.length];
        for(int i=0;i<oldfile.length;i++){
        oldfile[i]=new File(files[i]);
        int index = oldfile[i].getName().lastIndexOf('.');
          if (index>0&& index <= oldfile[i].getName().length() - 2 ) {
           st[i]=oldfile[i].getName().substring(0, index);
          } 
        }
        File newfile[] = new File[files.length];
        String filename[]=new String[files.length];
        for(int i=0;i<files.length;i++){
        filename[i]=st[i].replace("Angelrose0705$","RohitBBorse");
        newfile[i]=new File(filename[i]+".jpg");
        }

        for(int i=0;i<files.length;i++){
           boolean Rename = oldfile[i].renameTo(newfile[i]);
           if(Rename){
               System.out.println("Renamed Successfully!");
           }
        }
    }
}

May 3, 2012 at 9:58 PM


Thanks friend :)









Related Pages:
Renaming multiple files
Renaming multiple files  Hi, I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. .... Now I wanted to rename these files as: 1RohitBBorse.mp4
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
Dynamic include of multiple files
Dynamic include of multiple files  I want to include a series of small files, based on a string. For instance, if the string was: String fileString="a b c d e"; I would split it into an array, fileArray, and do something like
Merging multiple PDF files - Framework
Merging multiple PDF files  I m using the iText package to merge pdf files. Its working fine but on each corner of the merged filep there is some... the files are having different font.Please help
save output in multiple text files
save output in multiple text files  Hi..I'm getting problem to store the output of this php code into multiple text files. Can anyone sugeest. Here is my code: <?php for($i=1; $i<=100; $i++) { $html = file_get
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid... a file. In this example we are going to tell you how we can upload multiple files
Java read multiple files
Java read multiple files In this section you will learn how to read the data of multiple files. Here we have created four files that includes information.... We have to find the students according to particular school from all the files
Uploading the multiple files
. For uploading the multiple files at a time, first create a table as per required...; <HTML> <HEAD> <TITLE> Multiple Files Upload </TITLE>...="#FFFFFF"> <tr> <td><strong>Multiple Files
Copy multiple files
Copy multiple files        In this section, you will learn how the data of multiple files.... For copping the data of multiple file, you need all files in a specified directory where
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files... these two files and store in oracle database as: VendorID,Name,Address and plz
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Hi, I am trying to develop a file upload with multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
Source file upload by attaching multiple files
a provision to attach multiple images/files like in gmail. Is there any solution...Source file upload by attaching multiple files  Thanks for the answer. The answer posted in this link I want to have a single text box and when i
Uploading multiple files in JSP - JSP-Servlet
Uploading multiple files in JSP  Hi, I have this code in JSP for Uploading multiple files : Samples : Simple Upload... modification I need to do in the code to upload all the files attached. 
How to convert multiple files in java to .zip format
How to convert multiple files in java to .zip format  i receive multiple files from a remote URL as for (String reportid : reportList...://Answers//Examples"); File[] files = folder.listFiles(); File file=new File
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com... File(inpath); File files[]; files = Folder.listFiles
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp  ... to understand how you can upload multiple files by using the Jsp. We should avoid... a file. In this example we are going to tell you how we can upload multiple files
Mutliple files upload
Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit the form.Send em the answers as soon as possible..   Please visit
multiple language support iPhone
multiple language support iPhone  Is it possible to create an application in iPhone that can support multiple languages.   Yes, iPhone/iPad... the project location and create two project files for example en.lproj
Copy Files - Java Beginners
Copy Files  I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something... a list of JPEG files that my boss gave me, and I was planning on putting them
Multiple file upload - Struts
Multiple file upload  HI all, I m trying to upload multiple files using struts and jsp. I m using enctype="multipart". and the number of files... files uploaded Thanks  HI The code above will work
listing files - Java Beginners
]); System.exit(0); default : System.out.println("Multiple files...]); System.exit(0); default : System.out.println("Multiple files are not allow...listing files  how to list the files and number of files only
Uploading Multiple Image On Server?
;Struts 2 upload multiple files example</h1> <s:form action="resultAction...Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works
Directories and Files
Java NotesDirectories and Files Put all source files into a directory, one... for the source files. The directory name should be lowercase letters, with no blanks.... It's easy to do. Here are a couple of minor rules. Make sure all classes (.java files
files
/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code: import java.io.*; import java.util.*; class
retrieving image files - JSP-Servlet
retrieving image files  How to retrieve multiple images at a time from mysql database using JSP
multiple file upload at a time like gmail
multiple file upload at a time like gmail  I want to upload multiple files at a time like gmail. is there any possiblity/solution to do that?   Hi Friend, Please visit the following link: Upload Multiple Files Thanks
Java JAR Files
to bundle multiple files into a single archive file. Typically a JAR file format... Java JAR Files       A JAR file is a collection of  class files and auxiliary resources associated
Multiple file Uploading - JSP-Servlet
Multiple file Uploading   Hello everyone I am using jsp and my IDE is eclipse and back end is ms sql server i am trying to upload multiple files using the same code provided on the site and i am getting hell lot of errors
files upload to apache ftp server - Ajax
files upload to apache ftp server  Please, how to upload multiple files to apache ftp server using ajax . I want to upload files using drag drop style in javascript. I am okay for uploading files to ftpserver using command
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row  Hai, I need... table in multiple rows(which means one value for one row). eg: my file containes
files upload to apache ftp server - Ajax
files upload to apache ftp server  Please, how to upload multiple files to apache ftp server using ajax . I want to upload files using drag drop style in javascript. I am okay for uploading files to ftpserver using command
display multiple image file or pdf file in multiple column of a row from server or database
in a particular format i.e I have to display more than one files in multiple columns in a single row..Suppose I have to display two files in a row then after...display multiple image file or pdf file in multiple column of a row from server
create Multiple Lines
single  lines and how you can make multiple lines on the text in pdf files. You can make multiple lines and also make colorful lines by using... Create Multiple Lines    
how to search data in xml files using php
how to search data in xml files using php  So I want to create a website that allows me (or others) to type in a words and select a relevent search, and have it search multiple XML pages on server The XML documents are setup
upload files to apache ftp server - Ajax
upload files to apache ftp server  hi,sir I want to upload multiple files to apache ftp server. I am using ajax framework for j2ee.Now I am okay...."); // //Get the list of files on the remote server
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?  HELLO SIR, CAN ANYONE HELP ME OUT HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILES,IF I ENTER 4 EMPLOYEE DETAILS(NAME,ID,SALARY,EMAIL) ALL THE DETAILS OF 4
how to use javascript drag and drop files upload - Ajax
how to use javascript drag and drop files upload  Hi,Sir Please, I would like to upload multiple files using javascript with drag and drop style.I... for upload files in drag and drop style instead of using javascript.But I need
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi, java does not support multiple inheritance

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.