Solved

grabbing the name of a file

Posted on 2004-09-24
12
189 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 18

Accepted Solution

by:
armoghan earned 50 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

734 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