标题: [文件操作] [已解决]请教批处理文件分类无法到五级问题 [打印本页]
作者: hztyf_21558 时间: 2022-1-23 10:01 标题: [已解决]请教批处理文件分类无法到五级问题
有上百个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
复制代码
作者: qixiaobin0715 时间: 2022-1-23 10:59
本帖最后由 qixiaobin0715 于 2022-1-23 11:34 编辑
你的代码好乱,没仔细看。我猜你可能是要这样:- @echo off
- set _00001=张三
- set _00002=李四
- set _11=大车
- set _12=小车
- setlocal enabledelayedexpansion
- for /f "tokens=1-5 delims=_" %%a in ('dir /b /a-d *.MP4 *.JPG') do (
- set str=%%d
- set yy=!str:~,6!
- set dd=!str:~7,4!
- if not exist "!_%%c!\!yy!\!dd!\%%b\!_%%a!" md "!_%%c!\!yy!\!dd!\%%b\!_%%a!"
- move "%%a_%%b_%%c_%%d_%%e" "!_%%c!\!yy!\!dd!\%%b\!_%%a!"
- )
- pause
复制代码
作者: qixiaobin0715 时间: 2022-1-23 11:42
本帖最后由 qixiaobin0715 于 2022-1-23 11:44 编辑
回复 1# hztyf_21558
设置日期段时有笔误,已修改。(set dd那一行)
作者: hztyf_21558 时间: 2022-1-23 20:12
回复 3# qixiaobin0715
问题已解决,非常感谢!受益匪浅。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |