Java File Mod Change Chmod(boolean recursive, String permission, String directoryFile)

Here you can find the source of Chmod(boolean recursive, String permission, String directoryFile)

Description

Change permission of files and directories

License

Open Source License

Declaration

private static void Chmod(boolean recursive, String permission,
        String directoryFile) throws IOException 

Method Source Code

//package com.java2s;
/*/*  www .  ja  v  a 2s  .  c  o m*/
 *  SSHTools - VO Management Tool
 *
 *  Copyright (C) 2013 Siew Hoon Leong
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  You may also distribute it and/or modify it under the terms of the
 *  Apache style J2SSH Software License. A copy of which should have
 *  been provided with the distribution.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  License document supplied with your distribution for more details.
 *
 */

import java.io.IOException;

public class Main {
    /**
     * Change permission of files and directories
     */
    private static void Chmod(boolean recursive, String permission,
            String directoryFile) throws IOException {
        String osName = System.getProperty("os.name");
        String command = "chmod";
        if (recursive) {
            command += " -R";
        }

        if (osName.startsWith("Mac OS")) {
            Runtime.getRuntime().exec(
                    command + " " + permission + " " + directoryFile);
        } else if (osName.startsWith("Windows")) {
            //Nothing can be done currently
        } else {
            Runtime.getRuntime().exec(
                    command + " " + permission + " " + directoryFile);
        }
    }
}

Related

  1. chmod(@Nonnull File file, int mode)
  2. chmod(File file, int mode)
  3. chmod(File file, String mode)
  4. chmod(final int mode, final File path)
  5. chmod(final String path, final String mode)