简体   繁体   English

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

[英]Check a file path contains a specific directory name in it

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.包括 .svn 在内的所有图像文件也被复制。 Is there any way to exclude the file which contains a directory name .svn ?有没有办法排除包含目录名称.svn的文件? I may use fileFromList.contains(".svn") but if there is a file name like image.svn.check.jpg will also getting excluded.我可以使用fileFromList.contains(".svn")但如果有像image.svn.check.jpg这样的文件名也会被排除在外。 Is there any way to identify a file path which contains a specific directory name.有什么方法可以识别包含特定目录名称的文件路径。

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.如果是重复的,我很抱歉浪费了您的时间。

try this:尝试这个:

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

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" (eg 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));
        }
    }

Path扩展 Iterable ,因此您可以对其进行迭代并检查是否有任何部分以某些条件结束或等于某些条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM