检查文件路径中是否包含特定的目录名称

时间:2021-07-11 23:59:47

I'm working with a directory which is checked out from svn.

我正在使用从svn检出的目录。

Ex

HelloWorldProject

  • src
  • images

I'm manually copying entire files from images directory to one directory using commons-io

我使用commons-io手动将整个文件从images目录复制到一个目录

for (String fileFromList : imageFiles) {
    FileUtils.copyFile(new File(fileFromList) , new File(destinationFile));
}

All the files from images including .svn also getting copied. Is there any way to exclude the file which contains a directory name .svn? I may use fileFromList.contains(".svn") but if there is a file name like image.svn.check.jpg will also getting excluded. Is there any way to identify a file path which contains a specific directory name.

来自图像的所有文件(包括.svn)也会被复制。有没有办法排除包含目录名.svn的文件?我可以使用fileFromList.contains(“。svn”)但是如果有像image.svn.check.jpg这样的文件名也会被排除在外。有没有办法识别包含特定目录名称的文件路径。

Correct me if my understanding is wrong. I searched enough, I couldn't find anwer for this problem. If it's duplicate, I apology for wasted your time.

如果我的理解是错误的,请纠正我。我搜索得足够多,我找不到这个问题。如果它重复,我道歉浪费你的时间。

2 个解决方案

#1


try this:

for (String fileFromList : imageFiles) {
    if (!fileFromList.contains("/.svn/")
      FileUtils.copyFile(fileFromList , destinationFile);
}

#2


If you want to exclude files which has ".svn" as ending this will work:

如果要排除“.svn”结尾的文件,这将起作用:

for (String fileFromList : imageFiles) {
        if(!fileFromList.endsWith(".svn")){ 
            FileUtils.copyFile(new File(fileFromList) , new File(destinationFile));
        }
    }

If you want to check if a file is not in a directory named ".svn" (e.g. C://.svn/test.jpg) you should use:

如果要检查文件是否不在名为“.svn”的目录中(例如C://.svn/test.jpg),则应使用:

for (String fileFromList : imageFiles) {
        if(!fileFromList.contains("/.svn/")){ 
            FileUtils.copyFile(new File(fileFromList) , new File(destinationFile));
        }
    }

#1


try this:

for (String fileFromList : imageFiles) {
    if (!fileFromList.contains("/.svn/")
      FileUtils.copyFile(fileFromList , destinationFile);
}

#2


If you want to exclude files which has ".svn" as ending this will work:

如果要排除“.svn”结尾的文件,这将起作用:

for (String fileFromList : imageFiles) {
        if(!fileFromList.endsWith(".svn")){ 
            FileUtils.copyFile(new File(fileFromList) , new File(destinationFile));
        }
    }

If you want to check if a file is not in a directory named ".svn" (e.g. C://.svn/test.jpg) you should use:

如果要检查文件是否不在名为“.svn”的目录中(例如C://.svn/test.jpg),则应使用:

for (String fileFromList : imageFiles) {
        if(!fileFromList.contains("/.svn/")){ 
            FileUtils.copyFile(new File(fileFromList) , new File(destinationFile));
        }
    }