※ Copilot 질의 응답
Option Explicit
Sub RenameFiles_1()
'★★파일명에 "KakaoTalk_"가 포함되어 있으면 제거★★
Dim folderPath As String
Dim fileName As String
Dim newFileName As String
'지정폴더 경로 지정
'원하는 폴더 경로로 변경하세요
folderPath = "C:\Users\홍길동\Documents\지정폴더\"
'첫 번째 파일 가져오기
fileName = Dir(folderPath & "*.*")
Do While fileName <> ""
'파일명에 "KakaoTalk_"가 포함되어 있으면
If InStr(fileName, "KakaoTalk_") > 0 Then
'"KakaoTalk_" 제거한 새 이름 생성
newFileName = Replace(fileName, "KakaoTalk_", "")
'파일 이름 변경
Name folderPath & fileName As folderPath & newFileName
End If
'다음 파일로 이동
fileName = Dir
Loop
End Sub
Sub RenameFiles_2()
'★★파일명에 "KakaoTalk_"가 포함되어 있으면 제거 및 확장자 앞에 "shin" 붙이기★★
Dim folderPath As String
Dim fileName As String
Dim newFileName As String
Dim baseName As String
Dim ext As String
'지정폴더 경로 지정
folderPath = "C:\Users\홍길동\Documents\지정폴더\"
'첫 번째 파일 가져오기
fileName = Dir(folderPath & "*.*")
Do While fileName <> ""
'파일명에 "KakaoTalk_"가 포함되어 있으면
If InStr(fileName, "KakaoTalk_") > 0 Then
'확장자 분리
ext = Mid(fileName, InStrRev(fileName, "."))
baseName = Left(fileName, InStrRev(fileName, ".") - 1)
'"KakaoTalk_" 제거
baseName = Replace(baseName, "KakaoTalk_", "")
'새 이름: 확장자 앞에 "shin" 붙이기
newFileName = baseName & "_shin" & ext
'파일 이름 변경
Name folderPath & fileName As folderPath & newFileName
End If
'다음 파일로 이동
fileName = Dir
Loop
End Sub
Sub RenameFiles_3()
'★★일반적인 파일 확장자 앞에 "shin" 붙이기★★
Dim folderPath As String
Dim fileName As String
Dim newFileName As String
Dim baseName As String
Dim ext As String
'지정폴더 경로 지정
folderPath = "C:\Users\홍길동\Documents\지정폴더\"
'첫 번째 파일 가져오기
fileName = Dir(folderPath & "*.*")
Do While fileName <> ""
'확장자 분리
ext = Mid(fileName, InStrRev(fileName, "."))
baseName = Left(fileName, InStrRev(fileName, ".") - 1)
'파일명에서 "KakaoTalk_" 제거
baseName = Replace(baseName, "KakaoTalk_", "")
'새 이름: 확장자 앞에 "_shin" 붙이기
newFileName = baseName & "_shin" & ext
'파일 이름 변경
Name folderPath & fileName As folderPath & newFileName
'다음 파일로 이동
fileName = Dir
Loop
End Sub
'매크로 > 모듈(Module)' 카테고리의 다른 글
| 지정폴더 내 화일명 확장자 삭제 후 목록 가져오기 (0) | 2026.04.17 |
|---|---|
| 지정 폴더의 서브 폴더 목록 가져오기 (0) | 2026.03.27 |
| 시트를 순환하며 선택영역을 지정폴더에 JPG 출판(Ⅱ) (0) | 2026.01.28 |
| 시트의 선택영역을 지정 폴더에 PDF 출판 (0) | 2026.01.27 |
| 시트를 순환하며 선택영역을 지정폴더에 JPG 출판(Ⅰ) (0) | 2026.01.22 |