Results 1 to 5 of 5
  1. #1
    Stamoulohta is offline Member
    Join Date
    Mar 2011
    Posts
    26
    Rep Power
    0

    Question 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:
    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);
    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?

    ps: ls.length would not work because some files may be previously deleted...

    I thank you in advance,
    George.

  2. #2
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    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?

  3. #3
    Stamoulohta is offline Member
    Join Date
    Mar 2011
    Posts
    26
    Rep Power
    0

    Default

    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 ;)

  4. #4
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    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 07:26 PM.

  5. #5
    Stamoulohta is offline Member
    Join Date
    Mar 2011
    Posts
    26
    Rep Power
    0

    Default

    Hey!

    I didn't know about subSequence!! This seems great!!

    Thanks.

Similar Threads

  1. runing Java program increases continuing memory usage
    By henry123 in forum Advanced Java
    Replies: 12
    Last Post: 02-25-2011, 03:09 PM
  2. Display filenames in frame
    By cool in forum AWT / Swing
    Replies: 1
    Last Post: 11-19-2010, 03:51 PM
  3. Replies: 5
    Last Post: 01-27-2010, 10:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •