?
Solved

grabbing the name of a file

Posted on 2004-09-24
12
Medium Priority
?
191 Views
Last Modified: 2010-03-31
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
Comment
Question by:vcgDevelopers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12142877
File.getAbsolutePath()
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12142884
       File f = new File("C:\\images\\test.jpg");
        f.getName();
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12142903
Listing the Files or Subdirectories in a Directory: http://javaalmanac.com/egs/java.io/GetFiles.html
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Accepted Solution

by:
armoghan earned 200 total points
ID: 12142916
sorry this is the one
File f = new File("C:\\images\\test.jpg");
f.getParentFile().getName();

it will return images
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12142961
>> f.getName();
Do you need the name of the file given the full path?
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12142986
f.getName();
will give you name of the file and f.getParentFile().getName(); will give parent directory.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12143021
f.getParent() will also return the name of the parent directory
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12149963
What exactly does the questioner want?

;JOOP!
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12150030
Interesting question sciuriware :))

But he has all the options. He can use anyone of them :))
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12150089
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
 

Author Comment

by:vcgDevelopers
ID: 12162779
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 12162901
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question