vcgDevelopers
asked on
grabbing the name of a file
I need to grab the name of an image file stored in a folder, so that I can parse the name of the file.
C:\images\test.jpg
C:\images\test.jpg
File.getAbsolutePath()
File f = new File("C:\\images\\test.jpg ");
f.getName();
f.getName();
Listing the Files or Subdirectories in a Directory: http://javaalmanac.com/egs/java.io/GetFiles.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> f.getName();
Do you need the name of the file given the full path?
Do you need the name of the file given the full path?
f.getName();
will give you name of the file and f.getParentFile().getName( ); will give parent directory.
will give you name of the file and f.getParentFile().getName(
f.getParent() will also return the name of the parent directory
What exactly does the questioner want?
;JOOP!
;JOOP!
Interesting question sciuriware :))
But he has all the options. He can use anyone of them :))
But he has all the options. He can use anyone of them :))
I'm just curious, as he/she did not respond to the overwhelming food of answers.
I feel like the question was not correctly asked.
Chance to answer questioner!
;JOOP!
I feel like the question was not correctly asked.
Chance to answer questioner!
;JOOP!
ASKER
If I had a file (NCWV10024.jpg) I need to parse out 10024 as it is the identification number. An easy method to grab this was desired.
If it's always the last 5 characters of the "stem name" you might:
String s = "NCWV10024.jpg";
int dot = s.indexOf('.'); // check?
String parsed = s.subString(4, dot);
There you are.
;JOOP!
String s = "NCWV10024.jpg";
int dot = s.indexOf('.'); // check?
String parsed = s.subString(4, dot);
There you are.
;JOOP!