Skip to content

Instantly share code, notes, and snippets.

@nikuyoshi
Created July 8, 2015 03:57
Show Gist options
  • Save nikuyoshi/7c975432314c813922ac to your computer and use it in GitHub Desktop.
Save nikuyoshi/7c975432314c813922ac to your computer and use it in GitHub Desktop.
【Java】フォルダ内の指定した拡張子を一括削除する方法 ref: http://qiita.com/nikuyoshi/items/aae58b3beb182a0c1d2c
// 指定フォルダを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