배치를 빌드 한 적이 없으며 다음을 수행하는 구문을 찾는 데 어려움이 있습니다. 다음 논리에 따라 하위 폴더 (일부는 이미 존재하고 다른 일부는 생성 될)로 이동하려는 단일 디렉토리에 많은 파일이 저장되어 있습니다.
01202000088000.pdf
characters 1,2 -> first folder
characters 3,4 -> second folder
characters 5,6,7,8,9 -> third folder
01202000088000.pdf
파일을 로 이동해야 01\2020\00088\
하므로 이름 01202000088000.pdf
을 01\2020\00088\01202000088000.pdf
.
도움을 주시면 정말 감사하겠습니다.
편집 : 조언 덕분에 배치 버전도 만들었습니다.
@echo off
setlocal enabledelayedexpansion
rem For each file in your folder
for %%a in (*.pdf) do (
echo filename=%%a
rem check if the it is not our script
if "%%a" NEQ "%0" (
set foldername=%%a
set foldername=..\!foldername:~0,2!\!foldername:~2,4!\!foldername:~6,5!\
echo foldername=!foldername!
rem check if forlder exists, if not it is created
if not exist "!foldername!" mkdir "!foldername!"
rem Move (or change to copy) the file to directory
move "%%a" "!foldername!\"
)
)
역사 연구를하지 않는 한 batch 를 배울 이유가 없습니다 . PowerShell 사용 :
$Source = 'c:\PDF Folder'
GEt-ChildItem $Source *.pdf | ForEach{
$Destination = ($_.Name.Substring(0,2)),($_.Name.Substring(2,4)),($_.Name.Substring(6,5)) -join '\'
If ( -not ( Test-Path $Destination )) {
mkdir $Destination | out-null
}
Move-Item $_.FullName $Destination
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다