我需要刪除匹配的模式,其文件目錄下的所有目錄中的文件的某些文件:如何使用正則表達式來刪除SWIFT 3
myproject-(任何).sqlite-(任何)
現在,我做了,一個接一個:
let oldSqlitePath : NSString = documentsDirectory.appendingPathComponent("myproject-\(lastAppVersion!).sqlite") as NSString
let oldSqliteWalPath : NSString = documentsDirectory.appendingPathComponent("myproject-\(lastAppVersion!).sqlite-wal") as NSString
let oldSqliteShmPath : NSString = documentsDirectory.appendingPathComponent("myproject-\(lastAppVersion!).sqlite-shm") as NSString
do {
// delete the old SQLite file
try fileManager.removeItem(atPath: oldSqlitePath as String)
} catch _ {
}
do {
try fileManager.removeItem(atPath: oldSqliteWalPath as String)
} catch _ {
}
do {
try fileManager.removeItem(atPath: oldSqliteShmPath as String)
} catch _ {
}
我想使用正則表達式。
什麼是您的具體問題? – JeremyP
我沒有找到正確的方式來定義字符串myproject-(任何).sqlite-(任何)使用正則表達式。 – cmii
'myproject - [^。] * \。sqlite - 。*'並不完美,但應該有所斬斷。 – JeremyP