
- 帖子
- 6
- 积分
- 16
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2017-4-2
|
谢谢,因为中午qq2040486120大侠给出代码
如下:
@echo off
REM 开启变量延迟
setlocal enabledelayedexpansion
REM 搜索所有PDF文件
for /f "tokens=1* delims=年" %%a in ('dir /a-d /b *.PDF') do (
set "str=%%~na"
set "SN=!str:~0,6!"
set "EN=!str:~-4!"
if "!EN:~0,2!"=="20" (
REM 获取股票代码
if not defined ###_!SN!_ (
set "###_!SN!_=!EN!_!str:~0,-4!"
) else (
for %%I in (!SN!) do (set "tmp=!###_%%I_!")
set "tmp=!tmp:~0,4!"
if !EN! gtr !tmp! (
REM 获取最新年份股票名称
set "###_!SN!_=!EN!_!str:~0,-4!"
)
)
) else (
if not defined ###_!SN!_ (
for /f "tokens=1 delims=:" %%z in ("%%~na") do (
set "###_!SN!_=2000_%%z"
)
)
)
)
REM 根据股票代码创建文件夹
for /f "tokens=2,3* delims=_" %%a in ('set ###_') do (
set "str=%%c"
REM 去掉文件名中的冒号
if "!str:~-1!"==":" (
set "str=!str:~0,-1!"
) else if "!str:~-1!"==":" (
set "str=!str:~0,-1!"
)
REM 创建文件夹
md "!str!"
REM 按股票代码搜索PDF
for /f "delims=" %%A in ('dir /a-d /b /s "%%a*.PDF"') do (
REM 相同股票代码的PDF进行归类
echo 正在移动... "%%~nA"
move "%%A" "!str!"
)
)
REM 清理空文件夹
for /f "delims=" %%a in ('dir /ad /b') do (
if not exist "%%a\*.PDF" (
rd "%%a" /q
)
)
pause
谢谢taofan712 及WHY |
|