
각 하위 폴더가 배치 파일이나 명령줄에 지정된 최대 파일 양을 받는 한 단일 상위 폴더의 모든 파일을 필요한 만큼 많은 하위 폴더로 이동하려면 배치 파일 스크립트가 필요합니다. 즉, 스크립트는 상위 폴더의 모든 파일을 그 아래의 여러 하위 폴더(스크립트가 자동으로 생성해야 함)에 배포해야 하며, 파일을 여러 위치로 이동해야 합니다.엑스파일(여기서 "엑스"는 각 하위 폴더가 수신할 파일의 양입니다.)
추가 요구사항:
하위 폴더 이름은 001, 002, 003 등의 명명법에 따라 생성되어야 합니다.
모든 종류의 파일 이름(공백 포함, 특수 문자 또는 영어가 아닌 강조 표시 등)이 포함된 파일을 지원해야 합니다.
수만 개의 파일 이동을 지원해야 합니다.
로컬 관리자 권한으로 Windows 10 Professional에서 작업해야 합니다.
예를 들어, "D:\Downloads" 폴더에 2400개의 파일이 있고 이를 각각 최대 1000개의 파일이 포함된 하위 폴더에 배포하려고 한다고 가정해 보겠습니다. 스크립트를 실행하면 다음 구조가 생성됩니다.
D:\Downloads
|__001
|__002
|__003
어디:
D:\Downloads --> Will have no files inside it anymore
|__001 --> Will have 1000 files inside it
|__002 --> Will have 1000 files inside it
|__003 --> Will have the last 400 files inside it
파일의 순서(어떤 파일이 어떤 하위 폴더로 이동하는지)는 중요하지 않습니다. 즉, 이동 시 특정 기준(예: 파일 이름, 크기, 파일 유형 등)을 고려할 필요가 없습니다. 그러나 이 측면에 대한 개선 사항은 환영할 것입니다(예: 마지막으로 생성된 파일을 첫 번째 하위 폴더로 먼저 이동하는 옵션).
어떤 아이디어가 있나요?
업데이트
나를 위해 일한 솔루션은 다음과 같습니다.
@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
if not %3.==. goto syntax
if %2.==. goto syntax
:: Checks if %2 is a number:
SET "var="&for /f "delims=0123456789" %%i in ("%2") do set var=%%i
if defined var (goto syntax)
if /i %1.==. goto syntax
if /i not exist %1 echo. & echo The folder %1 does not exist... && echo Folder paths must be typed between "quotes" if there's any empty space. && echo. && goto end
setlocal enableextensions
setlocal enabledelayedexpansion
:: Maximum amount of files per subfolder:
SET limit=%2
:: Initial counter (everytime counter is 1, a new subfolder is created):
SET n=1
:: Subfolder counter:
SET nf=0
::Retrieves the amount of files in the specified folder:
set count=0
for %%A in (%1%\*.*) do set /a count+=1
echo.
echo Distributing %count% files in subfolders of up to %2 files...
FOR %%f IN (%1%\*.*) DO (
:: If counter is 1, create a new subfolder with name starting with "00...":
IF !n!==1 (
SET /A nf+=1
MD %1%\00!nf!
)
:: Move files into subfolders with names starting with "00...":
MOVE /-Y "%%f" %1%\00!nf! > NUL
:: Reset counter when a subfolder reaches the maximum file limit:
IF !n!==!limit! (
SET n=1
) ELSE (
SET /A n+=1
)
)
SET limit=
SET n=
SET nf=
SET count=
echo Move finished successfully.
goto end
:syntax
echo.
echo YOU TYPED: movedown %*
echo SYNTAX: movedown ["full path"] (between quotes if there's any space) [n] (maximum number of files per subfolder)
echo.
:end
ENDLOCAL