有上百个MP4、JPG文件,文件命名格式1~2位为项目,4~7位为类别,9~13位为姓名,15~20位为年月,21~24位为日期(如:11_0001_00001_20220102243438_0007)。姓名为一级文件夹,年月为二级文件夹,日期为三级文件夹,四级为类别文件夹,五级为项目文件夹。文件只能分类到四级类别文件夹下,不能到五级项目文件夹下,如下:- @echo off
- setlocal enabledelayedexpansion
-
- for %%a in (*.MP4 *.JPG) do (
- set "NameStr=%%~a"
- if not exist "!NameStr:~ 8,5!" md "!NameStr:~ 8,5!"
- move "%%~a" "!NameStr:~ 8,5!\"
- )
-
- ren 00001 张三
- ren 00002 李四
- move 00001\* 张三
- move 00002\* 李四
- rd 00001
- rd 00002
-
- for /d %%a in (*) do (
- pushd "%%~a"
- for %%a in (*.MP4 *.JPG) do (
- set "NameStr=%%~a"
- if not exist "!NameStr:~ 14,6!" md "!NameStr:~ 14,6!"
- move "%%~a" "!NameStr:~ 14,6!\"
- )
- popd
- )
-
- for /d %%a in (*) do (
- pushd "%%~a"
- for /d %%a in (*) do (
- pushd "%%~a"
- for %%a in (*.MP4 *.JPG) do (
- set "NameStr=%%~a"
- if not exist "!NameStr:~ 20,4!" md "!NameStr:~ 20,4!"
- move "%%~a" "!NameStr:~ 20,4!\"
- )
- popd
- )
- popd
- )
-
- for /d %%a in (*) do (
- pushd "%%~a"
- for /d %%a in (*) do (
- pushd "%%~a"
- for /d %%a in (*) do (
- pushd "%%~a"
- for %%a in (*.MP4 *.JPG) do (
- set "NameStr=%%~a"
- if not exist "!NameStr:~ 3,4!" md "!NameStr:~ 3,4!"
- move "%%~a" "!NameStr:~ 3,4!\"
- )
- popd
- )
- popd
- )
- popd
- )
-
- for /d %%a in (*) do (
- pushd "%%~a"
- for /d %%a in (*) do (
- pushd "%%~a"
- for /d %%a in (*) do (
- pushd "%%~a"
- for /d %%a in (*) do (
- pushd "%%~a"
- for %%a in (*.MP4 *.JPG) do (
- set "NameStr=%%~a"
- if not exist "!NameStr:~ 0,2!" md "!NameStr:~ 0,2!"
- move "%%~a" "!NameStr:~ 0,2!\"
- )
-
- ren 11 大车
- ren 12 小车
- move 11\* 大车
- move 12\* 小车
- rd 11
- rd 12
-
- for /d "tokens=*" %%a in ('dir /a:d /b') do (
- popd
- )
- popd
- )
- popd
- )
- popd
- )
- pause
- exit
复制代码
|