I’m fairly new to Java so please forgive me if this is a stupid question.
Basically, a file is a song. I’m using JFileChooser to select multiple songs. I then do some stuff with the array of songs (their file names and paths). I want to then create 2 directories inside the directory in which the songs are located, a directory for the artist name, and a directory for the album name inside the artist name directory. I then want to move the files in my array to the album directory.
I’m fairly sure I’m supposed to be using mkdirs() method.
How can I tell the program to make the directories in the location of the songs whose paths I have stored in an array of files? I can only find examples of getting rid of the extension, not the file name, to be able to use the path for the mkdirs() method.
Suppose you have some
File foothat points toc:\foo\bar\baz\music.wav, to get the parent directory you can useFile.getParentFile(). I recommend constructing the subdirectories using theFileconstructor:Since you’re sure that
subdir1‘s parent exists, you can get away callingsubdir1.mkdir()instead, but you won’t lose anything by callingmkdirs.