Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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