Link to home
Start Free TrialLog in
Avatar of vcgDevelopers
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
Avatar of zzynx
zzynx
Flag of Belgium image

File.getAbsolutePath()
       File f = new File("C:\\images\\test.jpg");
        f.getName();
Listing the Files or Subdirectories in a Directory: http://javaalmanac.com/egs/java.io/GetFiles.html
ASKER CERTIFIED SOLUTION
Avatar of armoghan
armoghan
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> f.getName();
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.
f.getParent() will also return the name of the parent directory
Avatar of sciuriware
sciuriware

What exactly does the questioner want?

;JOOP!
Interesting question sciuriware :))

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!
Avatar of vcgDevelopers

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!