• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting a filename

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, I would suggest that last part could be

or possibly
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic