aspose file tools*
The moose likes Java in General and the fly likes files are not beened deleted and renamed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "files are not beened deleted and renamed" Watch "files are not beened deleted and renamed" New topic
Author

files are not beened deleted and renamed

damodar kumar
Ranch Hand

Joined: May 19, 2008
Posts: 77


mine aim is path contains a.txt it have to renamed to a_1.txt and have to delete the a.txt and a_1.txt have to rename to a.txt bt happening is

1) if that path contains a.txt

2) it is named to a_1.txt

3) its not deleting the a.txt and a_1.txt is not renamed to a.txt.

please suggest me by checking the above code.

Thanks

Damodar

[ June 16, 2008: Message edited by: damodar kumar ]
[ June 16, 2008: Message edited by: damodar kumar ]

<a href="http://stackoverflow.com/users/668970/user668970" rel="nofollow">
<img src="http://stackoverflow.com/users/flair/668970.png" >
</a>
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3681
    
  16
Can you edit your post (click on the paper and pencil icon) and put your code into code tags. This will make it much easier to read.
It's difficult to read your code but the only code i could see that you might be using to delete a file is a call to deleteOnExit. This will not delete the file until you exit the JVM (i.e. your program finishes). Try using the delete method instead and see if that fixes your problem.


Joanne
Ravikanth kolli
Ranch Hand

Joined: Feb 10, 2008
Posts: 179

I dont think deleteOnExit works since the file is deleted only during the virtual machine termination.

More information can be found here

you can try something like delete.

file is not renamed because a file with the same name already exists.
[ June 16, 2008: Message edited by: Ravikanth kolli ]

-kolli
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Apparently, this is continued from here. Damodar, in general it's better to continue a topic in the same thread you started in, if you're really just continuing the exact same discussion. That way people have access to all the earlier info and don't waste time saying things that have already been said before. Thanks.


"I'm not back." - Bill Harding, Twister
damodar kumar
Ranch Hand

Joined: May 19, 2008
Posts: 77

hi Jim Yingst

may be this come under same thread, but i got some different answer, which i not got with previous thread. there was no time wasting as i not mentioned, that please refer previous thread for more information , i mentined every thing clearly in the present thread.Also the code what i metioned before is different with the previous thread.
Yashpal Rawat
Greenhorn

Joined: Jun 19, 2008
Posts: 4
Hey, I have some suggestions/queries

1. Is this a standalone program? If yes then deleteOnExit should work since
your jvm will exit once you are done with your program.
2. If you intend to only renmae the file then why you are not using only
renameTo method in File Class.
3. I think variable newname should be reset in each iteration
4. Also its not clear what is to be done in case directory have all files
already renamed.

I have modified your code below with assumption that if both old and new file you wanted to create already exists then new file will be over-written.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yashu23

Please check your private messages. Thanks.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Vilmantas Baranauskas
Ranch Hand

Joined: Dec 20, 2006
Posts: 89
Some suggestions to improve/simplify your code:

Use fileslist[i].endsWith(".pdf") instead of


Use


instead of



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: files are not beened deleted and renamed