Created
July 8, 2015 03:57
-
-
Save nikuyoshi/7c975432314c813922ac to your computer and use it in GitHub Desktop.
【Java】フォルダ内の指定した拡張子を一括削除する方法 ref: http://qiita.com/nikuyoshi/items/aae58b3beb182a0c1d2c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 指定フォルダをhogeとする。 | |
Path path = Paths.get("C:","hoge"); | |
try(DirectoryStream<Path> ds = Files.newDirectoryStream(path, "*.txt") ){ | |
for(Path deleteFilePath : ds){ | |
System.out.println("次のファイルを削除します。: " + deleteFilePath.toString()); | |
Files.delete(deleteFilePath); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment