我目前有一個腳本,通過正則表達式包含和排除將文件從源目錄復制到目標目錄,但是當路徑包含括號時,文件將不會復制。我最初的想法是,問題在于如何讀取源和目標,因為 ( 是一個特殊字符,為了對抗我試圖用轉義的 (,但我可能做錯了那部分。import groovy.io.FileTypeimport java.nio.file.* String Source = 'C:/temp/file(s)' String Target = 'C:/newTemp/file(s)' String InclusionsRegexes = "garbage.txt" String ExclusionsRegexes = "" class RegexInfo { private String AllRegexes = ""; public RegexInfo(String RegexString, String RegexType, String Source) { if(RegexString != null) { def RegexArray = RegexString.split(","); for(item in RegexArray) { String fullRegexPath = Source + "/" + item; if(AllRegexes != null && !AllRegexes.isAllWhitespace()) { //Add regex value for Or AllRegexes += "|"; } AllRegexes += fullRegexPath; } } } public String getAllRegexes() { return this.AllRegexes; } } IncludesRegexInfo = new RegexInfo(InclusionsRegexes, "inclusion", Source); ExcludesRegexInfo = new RegexInfo(ExclusionsRegexes, "exclusion", Source); File SourceDirToCopy = new File(Source); SourceDirToCopy.eachFileRecurse() { SourceFile -> String SourceFilePath = SourceFile.toString().replaceAll("\\\\","/"); if(SourceFile.isDirectory()) { SourceFilePath += "/" }我收到的錯誤要么是意外字符,要么是文件沒有錯誤地移動。
Groovy/Java - 復制文件路徑中帶有括號的問題
慕尼黑8549860
2023-02-23 10:49:27