File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Using Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using Files" Watch "Using Files" New topic
Author

Using Files

Shashidhar Yarabati
Ranch Hand

Joined: Jun 17, 2007
Posts: 175
Hi

I have a lot of files in particular folder. say "cvsadmin". It has lot of subdirectories, which itself contains lot of files in it.
What I want to do is: The file names which has ",v" extension needs to renamed.

I know we can do this for a particular file. But my folder has lots of files like this. I can go individually.

Could any body tell me the any solution?
Waiting for your reply..


Shashidhar<br /> SCJP 1.5<br /> SCWCD 5.0
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

You cant do it in a single command, if this is what you were asking.
If you are not sure, how to get a list of the all the files with a specified extension, then have a look at File.listfiles() method. This will give you a list of all immediate children of a directory. To drill down deep you can recursively process each child which is a directory.

BTW, not an advanced question.
[ June 04, 2008: Message edited by: Nitesh Kant ]

apigee, a better way to API!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

Additionally, you can use File's renameTo method to rename the file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
Don't know your context but sometimes tasks may be accomplished easier without java, e.g. on linux/unix command line:

find . -name "*,v" -exec mv \{\} \{\}.new \;

will move all "*,v" files to "*,v.new".


Author of <a href="http://www.newsinjector.com" target="_blank" rel="nofollow">NewsInjector</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Files
 
Similar Threads
File
access control and jsp
how to copy a file from one folder to another folder?
how to include jar in jar
How to delete all existing files in a dierectry?