标题: [文本处理] [分享]批处理根据xpl文件内容复制文件 [打印本页]
作者: Batcher 时间: 2023-8-21 18:17 标题: [分享]批处理根据xpl文件内容复制文件
【问题描述】- @echo off
- cd /d "%~dp0"
- set "NewFolder=我自己创建的"
- if not exist "%NewFolder%" (
- md "%NewFolder%"
- )
- for /f "delims=" %%i in ('dir /b /a-d *.xpl') do (
- echo --- %%i
- for /f tokens^=2^ delims^=^" %%a in ('type "%%i" ^| findstr "filename"') do (
- set "MyFile=%%a"
- setlocal enabledelayedexpansion
- set "MyFile=!MyFile:\\isilon.zf.com\ADASdata\=Z:\!"
- echo xcopy /y "!MyFile!" "!NewFolder!"
- xcopy /y "!MyFile!" "!NewFolder!"
- endlocal
- )
- )
- pause
复制代码
就是针对上周的脚本又出现了新的需求
1.每个xpl文件里面读取的文件放到以xpl文件命名的文件夹
2.根据读取到的xpl文件内容找到前两分钟和后一分钟的文件
https://pan.baidu.com/s/1BTfzhFcD18uvPoGjFjQRlA?pwd=9wf4
就以这个为例
里面的文件名最后是619.sdf
往前两分钟就是617,618,往后一分钟就是620
最小的是001.sdf,最大的是999.sdf
不会超过这个区间
作者: Batcher 时间: 2023-8-21 18:18
【解决方案】
放到以xpl文件命名的文件夹.bat- @echo off
- cd /d "%~dp0"
- for /f "delims=" %%i in ('dir /b /a-d *.xpl') do (
- echo --- %%i
- for /f tokens^=2^ delims^=^" %%a in ('type "%%i" ^| findstr "filename"') do (
- set "MyFile=%%a"
- setlocal enabledelayedexpansion
- set "MyFile=!MyFile:\\isilon.zf.com\ADASdata\=Z:\!"
- set "NewFolder=%%~ni"
- if not exist "!NewFolder!" (
- md "!NewFolder!"
- )
- echo xcopy /y "!MyFile!" "!NewFolder!"
- xcopy /y "!MyFile!" "!NewFolder!"
- endlocal
- )
- )
- pause
复制代码
作者: Batcher 时间: 2023-8-21 18:18
1+2.bat- @echo off
- cd /d "%~dp0"
- for /f "delims=" %%i in ('dir /b /a-d *.xpl') do (
- echo --- %%i
- for /f tokens^=2^ delims^=^" %%a in ('type "%%i" ^| findstr "filename"') do (
- set "MyFile=%%a"
- setlocal enabledelayedexpansion
- set "MyFile=!MyFile:\\isilon.zf.com\ADASdata\=Z:\!"
- set "NewFolder=%%~ni"
- if not exist "!NewFolder!" (
- md "!NewFolder!"
- )
- echo xcopy /y "!MyFile!" "!NewFolder!"
- xcopy /y "!MyFile!" "!NewFolder!"
- set "FileThis=1!MyFile:~-7,3!"
- set /a FileBefore2=FileThis-2
- set /a FileBefore1=FileThis-1
- set /a FileAfter1=FileThis+1
- if !FileThis! equ 1001 (
- xcopy /y "!MyFile:~0,-8!!FileAfter1:~1!%%~xa" "!NewFolder!"
- ) else if !FileThis! equ 1002 (
- xcopy /y "!MyFile:~0,-8!!FileBefore1:~1!%%~xa" "!NewFolder!"
- xcopy /y "!MyFile:~0,-8!!FileAfter1:~1!%%~xa" "!NewFolder!"
- ) else if !FileThis! equ 1999 (
- xcopy /y "!MyFile:~0,-8!!FileBefore2:~1!%%~xa" "!NewFolder!"
- xcopy /y "!MyFile:~0,-8!!FileBefore1:~1!%%~xa" "!NewFolder!"
- ) else (
- xcopy /y "!MyFile:~0,-8!!FileBefore2:~1!%%~xa" "!NewFolder!"
- xcopy /y "!MyFile:~0,-8!!FileBefore1:~1!%%~xa" "!NewFolder!"
- xcopy /y "!MyFile:~0,-8!!FileAfter1:~1!%%~xa" "!NewFolder!"
- )
- endlocal
- )
- )
- pause
复制代码
作者: yyz219 时间: 2023-8-22 07:59
1+2.bat
Batcher 发表于 2023-8-21 18:18
谢谢分享
作者: jszw666 时间: 2023-8-22 09:17
鼓励辛苦了!学习
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |