Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Deleting Full Directories?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Krocker




PostPosted: Sat Dec 31, 2011 11:16 am   Post subject: Deleting Full Directories?

hey guys, i have been working on a program that deletes specific files such as temporary files. Im making the mian structure first, but i keep getting an error at
for (String temp;files;); it says that files is not a bolean, but in the example form which i used to help me it shows that the files is in the correct place. heres my codes:



code:


package delete.file;

import java.io.File;
import java.io.IOException;

public class DeleteDirectoryExample
{
    private static final String SRC_FOLDER = "C:\\Nexon/BlackCipher";

    public static void main (String[] args)
    {

        File directory = new File (SRC_FOLDER);

        //make sure directory exists
        if (!directory.exists ())
        {

            System.out.println ("Directory does not exist.");
            System.exit (0);

        }
        else
        {

            try
            {

                delete (directory);

            }
            catch (IOException e)
            {
                e.printStackTrace ();
                System.exit (0);
            }
        }

        System.out.println ("Done");
    }


    public static void delete (File file)
        throws IOException
    {

        if (file.isDirectory ())
        {

            //directory is empty, then delete it
            if (file.list ().length == 0)
            {

                file.delete ();
                System.out.println ("Directory is deleted : "
                        + file.getAbsolutePath ());

            }
            else
            {

                //list all the directory contents
                String files[] = file.list ();

                for (String temp;files;); // HERES THE ERROR
                {
                    //construct the file structure
                    File fileDelete = new File (file, temp);

                    //recursive delete
                    delete (fileDelete);
                }

                //check the directory again, if empty then delete it
                if (file.list ().length == 0)
                {
                    file.delete ();
                    System.out.println ("Directory is deleted : "
                            + file.getAbsolutePath ());
                }
            }

        }
        else
        {
            //if file, then delete it
            file.delete ();
            System.out.println ("File is deleted : " + file.getAbsolutePath ());
        }
    }
}
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: