• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

getting a filename  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to make a database of an mp3 collection where all the mp3's are actually .txt files with nothing in them. I have to put them in some kind of collection which shouldnt be a problem for me. The problem is that I don't know how to get the file and folder names themselves in order to add them to the database. So folder names would be like "Rolling Stones - 40 Licks" with file names within being "01 - Same Old Crap.txt" I have no idea where to start on this, any help is appreciated, thanks!
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use the java.io.File class. It has methods to let you list all files and directories within a directory and methods to determine whether it is a file or directory.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think
File file = new File(name);
name is file name or folder.

and detect file music follow by
if(file.isFile()){

if( file.getName().indexOf(".mp3") > 0);
System.out.print("this is a file mp3");
}
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is correct but a small addition if you do not mind

=====================
I think
File file = new File(name);
name is file name or folder.

and detect file music follow by
if(file.isFile()){

if( file.getName().indexOf(".mp3") > 0);
System.out.print("this is a file mp3");
}

======================================
File file = new File(name);

if(file.isFile()){
String fileName = file.getName();

if( (fileName.lastIndexOf(".mp3")+1) ==
(fileName.length()-".mp3".length())
)
System.out.print("this is a file mp3");
}


Even better is to place the extension in a Constant and use that.
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, I would suggest that last part could be

or possibly
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!