• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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
0
vcgDevelopers
Asked:
vcgDevelopers
  • 4
  • 4
  • 3
  • +1
1 Solution
 
zzynxSoftware engineerCommented:
File.getAbsolutePath()
0
 
armoghanCommented:
       File f = new File("C:\\images\\test.jpg");
        f.getName();
0
 
zzynxSoftware engineerCommented:
Listing the Files or Subdirectories in a Directory: http://javaalmanac.com/egs/java.io/GetFiles.html
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
armoghanCommented:
sorry this is the one
File f = new File("C:\\images\\test.jpg");
f.getParentFile().getName();

it will return images
0
 
zzynxSoftware engineerCommented:
>> f.getName();
Do you need the name of the file given the full path?
0
 
armoghanCommented:
f.getName();
will give you name of the file and f.getParentFile().getName(); will give parent directory.
0
 
zzynxSoftware engineerCommented:
f.getParent() will also return the name of the parent directory
0
 
sciuriwareCommented:
What exactly does the questioner want?

;JOOP!
0
 
armoghanCommented:
Interesting question sciuriware :))

But he has all the options. He can use anyone of them :))
0
 
sciuriwareCommented:
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!
0
 
vcgDevelopersAuthor Commented:
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.

0
 
sciuriwareCommented:
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!
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now