Here is a solution using Apache Commons.IO FileUtils and the corresponding File methods.
for (File f : FileUtils.listFilesAndDirs(new File('/some/path'), TrueFileFilter.TRUE, TrueFileFilter.TRUE)) { if (!f.setReadable(true, false)) { throw new IOException(String.format("Failed to setReadable for all on %s", f)); } if (!f.setWritable(true, false)) { throw new IOException(String.format("Failed to setWritable for all on %s", f)); } if (!f.setExecutable(true, false)) { throw new IOException(String.format("Failed to setExecutable for all on %s", f)); } }
This is the equivalent of chmod -R 0777 /some/path . Adjust the calls to set{Read,Writ,Execut}able to implement other modes. (I would love to update this answer if someone posted the appropriate code for this.)
source share