How to delete all files from a directory using Fileutils.cleanDirectory();

Asked

Viewed 20 times

-1

I am trying to delete all files from within a folder, but not delete the folder itself, I have been recommended to use Fileutils.cleanDirectory(), however, I cannot specify the folder I want it to delete content, my command is like this:

FileUtils.cleanDirectory("C:\PAYGO\RESP"); 

in this way the netbeans gives error saying that a String cannot be converted into a File, so as I could specify the folder?

3 answers

0

Remember that the \ is used for escape sequences. Try using "C:\\PAYGO\\RESP".

0

Have you tried inserting path directory as if it were a regex:

C: PAYGO RESP*

0

I managed to solve the problem as follows:

File resp = new File("C:/PAYGO/RESP");

FileUtils.cleanDirectory(resp);

I had to create a file and put the path of the folder inside it, but thank you all for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.