Skip to content

BAT script: Create directories in batches based on file names and move files into them

Original link: https://www.itylq.com/bat-create-directory-and-move-in.html

Release date: 2022-09-17 Migration time: 2026-03-21

I recently organized the NAS space and found that there are really a lot of files in the movie directory, including video files, subtitle files, cover images, nfo, vsmeta, etc... There are at least five or six files related to a movie, and it is no longer possible to visually display how many movies there are. When there is a need, there will be an idea. Well, it should be the most convenient to reorganize it using the movie name as the directory. Do you manually create folders one by one and then cut and paste? No, no, no, that is too inefficient. It is more convenient to run it with a bat script.

1 Extract file name to TXT file

dir /B X:\MOVIE >d:\list.txt
#X:\MOVIE maps the NAS shared folder to the local path

2 Intercept the movie name to create a directory

for /f "tokens=1 delims=." %%a in ('type list.txt') do md %%a
#Use the symbol "." as the delimiter to extract the first part of the txt information to create a directory

3 Batch move files into a new directory based on movie names

move %%a* %%a

The complete code is as follows:

dir /B X:\MOVIE >d:\list.txt
for /f "tokens=1 delims=." %%a in ('type list.txt') do md %%a && move %%a* %%a

4 Effect Illustration


This article was moved from WordPress to MkDocs