Results 1 to 5 of 5
Thread: Continuing Filenames
- 04-04-2011, 02:08 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 26
- Rep Power
- 0
Continuing Filenames
Hello friends,
I'm trying to write this application that will save some files to the disk enumerating their names. My problem is that when I restart the app I want to continue the file-saving process from where it was left..
My files will ALWAYS be like:
test_1.jpg
test_2.jpg
test_3.jpg
etc...
what I've done up to now is:but now I don't know how to extract the greatest number from the filenames... Is there an nice and clever way to go about it or should I overkill using re?Java Code:File path = new File(filepath); FilenameFilter fil = new FilenameFilter(){ @Override public boolean accept(File dir, String filename) { String lowercaseName = filename.toLowerCase(); if (lowercaseName.endsWith(".jpg")) { return true; } else { return false; } } }; if(path.isDirectory()){ String[] ls = path.list(fil);
ps: ls.length would not work because some files may be previously deleted...
I thank you in advance,
George.
- 04-04-2011, 02:33 PM #2
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
As an easy solution maybe keep a separate txt file that you can parse when app is loading that keeps the last index you used?
- 04-04-2011, 03:38 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 26
- Rep Power
- 0
well, thank you for replying,
but my application is very resource restricted and because multiple directories may be created containing the pre-mentioned files, I would prefer doing it some way without "littering" the file-system.
that being said, I stumbled upon org.apache.commons.lang.StringUtils; while googleing, that seemed useful for getting the differences out of the strings, convert them to integers and comparing them but this collection is not included in the android sdk and I am reluctant of using it...
any proposals would be great.
Thanks ;)
- 04-04-2011, 06:20 PM #4
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
Well maybe populate the files in the current folder and since the name format is standard you could get the names and get the bigger number of those. Like having 3 files and getting their filenames, "test-1.jpg", "test-4.jpg", "test-12.jpg" you know that if you get rid the 5 first and 4 last letters of the String you could get the numbering.
Like: fileName.subSequence(5,fileName.length-4)
Put those in a int[] and get Max...Last edited by santeron; 04-04-2011 at 06:26 PM.
- 04-04-2011, 06:37 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
runing Java program increases continuing memory usage
By henry123 in forum Advanced JavaReplies: 12Last Post: 02-25-2011, 02:09 PM -
Display filenames in frame
By cool in forum AWT / SwingReplies: 1Last Post: 11-19-2010, 02:51 PM -
How to get all filenames of certain file types in a folder?
By Mippzon in forum New To JavaReplies: 5Last Post: 01-27-2010, 09:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks