-
[VB.Net] 파일 생성일자로 폴더 생성 후 파일이동VB(A) 2017. 6. 4. 21:15
옛날 사진들이 한 폴더에 왕창 모여있는데
iPhoto는 날짜별로 알아서 분류해주는 기능이 있었는데
Photos로 넘어오면서 그런 기능이 없어져버려서 사진 관리에 어려움이 생겼다.
하여 사진생성날짜를 기준으로 폴더별로 분류해주는 코드를 짬.
이 파일들은 마지막 수정한 날짜를 검색해야 생성한 날짜를 뱉는 바람에
고민고민 하다가 수정한 날짜를 뽑아내는 코드를 짰다.
이미지 생성일자를 가져오는 메소드도 있는데
이 파일에는 적용이 안 돼서.. 할 수 없이 파일 생성일자를 가져옴.
원본이 아니라 한번 편집한 파일이라서 그럴지도..
Option Explicit OnImports System.IOPublic Class Form1Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.LoadDim SelectedFolder As StringDim myDate As DateDim DateFolder As StringTry'사진을 날짜별로 분류할 폴더를 선택합니다.With FolderBrowserDialog1.ShowDialog()SelectedFolder = .SelectedPathEnd With'폴더 내의 파일을 순환합니다.For Each LogFile In Directory.GetFiles(SelectedFolder)myDate = GetDatePictureTaken(LogFile) '사진 파일이 찍힌 날짜DateFolder = SelectedFolder & "\" & myDate '날짜명의 폴더'날짜 폴더가 없으면 폴더 생성If Not Directory.Exists(DateFolder) ThenDirectory.CreateDirectory(DateFolder)End If'날짜 폴더로 사진 이동File.Move(LogFile, DateFolder & "\" & Path.GetFileName(LogFile))NextCatch ex As ExceptionMsgBox(ex.Message)Exit SubEnd TryClose()End SubPublic Shared Function GetDatePictureTaken(path As String) As Date'사진 찍은 날짜 가져오기Dim fileCreatedDate As Date = File.GetLastWriteTime(path)Return Date.Parse(fileCreatedDate).ToShortDateStringEnd FunctionEnd Classcs 'VB(A)' 카테고리의 다른 글
월보 취합 서식 (0) 2017.08.29 난수 생성기(로또) (0) 2017.06.24 [VB.Net] 화면보호기 (0) 2017.06.03 지역별로 시트 생성하여 나누기 (0) 2017.05.16 주식표 변경(상승, 하락 글꼴변경, 주요 금액단위 변경) (0) 2017.05.07 댓글