I have been trying to make a program that renames several .mp4 file to the name of the folder it is in.The program works sometimes on a few files but eventually throws a null pointer exception
I have tried multiple different ways but none seem to work properly and I am not very familiar with windows 7-relevant java.
Can anybody see the problem? Cheers.
public static void main (String []args) throws InterruptedException
{
String dir = "D:\\New folder";
File directory = new File(dir);
File[] files = directory.listFiles();
File tempd;
File[] tempf;
String temps;
int filecount = 0;
for (int index = 0; index < files.length; index++)
{
temps = files[index].toString();
tempd = new File(temps);
tempf = tempd.listFiles();
for (int i = 0; i < tempf.length; i++)
{
String[] tempsRel = temps.split("\\\\");
if (tempf[i].toString().endsWith("mp4"))
{
boolean success = tempf[i].renameTo(new File(dir + "\\" + tempsRel[tempsRel.length-1] + ".mp4"));
if (success)
{
System.out.println("RENAMED FILE ==> " + tempsRel[tempsRel.length-1] + ".mp4");
}}}}
System.exit(0);
}