Skip to content

FileUtils.moveDir();只能移动文件夹里的文件到目标文件夹,但是源文件夹本身没有移动。 #1383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mao19951015 opened this issue Dec 2, 2020 · 0 comments
Assignees
Labels

Comments

@mao19951015
Copy link

描述 Bug

FileUtils.moveDir();只能移动文件夹里的文件到目标文件夹,源文件夹本身没有移动。
源文件夹只是被删掉了,感觉这样并不符合语义啊。 这样叫FileUtils.moveFilesInDir();会不会更好。

  • AndroidUtilCode 的版本:utilcode:1.30.5
  • 出现 Bug 的设备型号:所有
  • 设备的 Android 版本:所有

相关代码

private static boolean copyOrMoveDir(final File srcDir,
                                     final File destDir,
                                     final OnReplaceListener listener,
                                     final boolean isMove) {
    if (srcDir == null || destDir == null) return false;
    // destDir's path locate in srcDir's path then return false
    String srcPath = srcDir.getPath() + File.separator;
    String destPath = destDir.getPath() + File.separator;
    if (destPath.contains(srcPath)) return false;
    if (!srcDir.exists() || !srcDir.isDirectory()) return false;

    if (!createOrExistsDir(destDir)) return false;    //****感觉这里的参数换成destDir.getPath + "/" + srcDir.getName()会更好*****

    File[] files = srcDir.listFiles();
    if (files != null && files.length > 0) {
        for (File file : files) {
            File oneDestFile = new File(destPath + file.getName());
            if (file.isFile()) {
                if (!copyOrMoveFile(file, oneDestFile, listener, isMove)) return false;
            } else if (file.isDirectory()) {
                if (!copyOrMoveDir(file, oneDestFile, listener, isMove)) return false;
            }
        }
    }
    return !isMove || deleteDir(srcDir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants