[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [已解决]BAT批处理如何按要求移动文件?

本帖最后由 DDDYJQ1 于 2014-4-8 13:47 编辑

文件夹下有上千个.HTM文件,文件名如下
文件名                             要创建的文件夹名
content.asp@uni=E401.html         E4
content.asp@uni=2F73.html         2F
content.asp@uni=E402.html         E4
content.asp@uni=052611.html       052
content.asp@uni=052543.html       052
content.asp@uni=052B26.html       052
content.asp@uni=052550.html       052
content.asp@uni=052C11.html       052
content.asp@uni=052609.html       052
content.asp@uni=052610.html       052
content.asp@uni=052541.html       052
content.asp@uni=2F879.html        2F
content.asp@uni=052612.html       052
content.asp@uni=052615.html       052
content.asp@uni=21482.html        214
content.asp@uni=29B5A.html        29
content.asp@uni=29B5B.html        29
content.asp@uni=29B5C.html        29
content.asp@uni=29B5D.html        29
content.asp@uni=180500.html       180
想按等号后的部分,创建文件夹,有四个字符的,创建文件夹为前两个字符,有五个字符的,也创建文件夹名为前两个字符,有六个文件名的,创建文件夹名为前三个字符,并移入新创建的文件夹中。不知表达是否清楚,先谢了,
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

有6个以上字符怎么处理 比如8个字符

TOP

  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in ('dir /b /a-d *.html') do (
  3.     for /f "tokens=2delims==" %%j in ("%%~ni") do (
  4.         set str=%%j
  5.         if "!str:~5!" == "" (
  6.             md "!str:~,2!" 2>nul
  7.         ) else md "!str:~,3!" 2>nul
  8.     )
  9. )
  10. pause
复制代码

TOP

  1. @echo off&setlocal EnableDelayedExpansion
  2. (for %%a in (*.html) do (
  3.     for /f "tokens=1* delims==" %%b in ("%%~na") do (
  4.         set "str=%%c"
  5.         if defined str if "!str:~5!"=="" (set "str=!str:~,2!")else set "str=!str:~,3!"
  6.     )
  7.     md "!str!"
  8.     move "%%a" "!str!\"
  9. ))2>nul
复制代码
1

评分人数

初学BAT,非专业。代码不适当之处还望前辈们多多指点。在此表示感谢!

TOP

谢谢各位,最多只有六个字行,3楼的只建立文件夹,4楼的可以,谢了

TOP

返回列表