728x90
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JsonFilesDelete
{
internal class FileName
{
static void Main(string[] args)
{
try
{
string rootPath = @"G:\fireProject_240105\화재 발생 예측 영상\Training\[라벨]화재씬\"; //json을 읽어올 경로
string[] files = Directory.GetFiles(rootPath, "*.json", SearchOption.AllDirectories);
foreach (var file in files)
{
File.Delete(file);
Console.WriteLine(file);
}
}
catch
{
}
}
}
}
- rootpath 에 검사할 대상 디렉터리를 쓰기 (최상단)
- Directory.GetFiles(rootPath, "*.json", SearchOption.AllDirectories); 에 "*.json" 부분에 검사할 확장자 작성하기
- SearchOption.AllDirectories -> 하위 디렉터리까지 검사
728x90
'c#' 카테고리의 다른 글
[c#] Dictionary 의 value 값이 Dictionary 일 경우 데이터 추가하기 (0) | 2023.11.28 |
---|---|
[c#] tiff 파일을 jpg로 변환하는 프로그램 (0) | 2023.08.01 |
[c#] 문자열이 숫자인지 확인 & 문자열 자르기 (0) | 2023.04.06 |
[c#] ftp에서 불러온 파일을 저장할 때, 같은 이름의 파일이 있을 경우 넘버링(숫자) 해주기 (0) | 2023.03.29 |
[c#] FTP에서 매개변수 "logName"을 파일 명으로 가진 파일을 다운로드하는 창 띄우기 (0) | 2023.03.27 |