当前位置: 首页 > news >正文

windows搬运文件脚本

使用方法:

copy_files_by_prefix.bat [目标目录] [结果目录] [文件名前缀] [可选参数:文件包含内容]

@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion:: Check parameters
if "%~3"=="" (echo Usage: %~nx0 [SourceDir] [TargetDir] [FilePrefix] [OptionalContent]echo Example: %~nx0 "C:\source" "D:\backup" "doc_" "123"goto :eof
):: Get parameters
set "source_dir=%~1"
set "target_dir=%~2"
set "prefix=%~3"
set "keyword=%~4":: Check if source directory exists
if not exist "%source_dir%\" (echo Error: Source directory does not exist - "%source_dir%"goto :eof
):: Create target directory if not exists
if not exist "%target_dir%\" (mkdir "%target_dir%"echo Created target directory: "%target_dir%"
):: Initialize counter
set file_count=0:: Scan and copy files
echo Scanning "%source_dir%\" for files starting with "%prefix%"...for /r "%source_dir%" %%f in ("%prefix%*") do (set "file_path=%%f"set "file_name=%%~nxf"if defined keyword (findstr /C:"!keyword!" "%%f" >nul 2>nulif errorlevel 1 (rem echo Skipping: %%f) else (set /a file_count+=1echo Copying: "!file_path!" to "%target_dir%\!file_name!"copy "!file_path!" "%target_dir%\" >nul)) else (set /a file_count+=1echo Copying: "!file_path!" to "%target_dir%\!file_name!"copy "!file_path!" "%target_dir%\" >nul)
):: Show results
echo.
echo Operation completed!
echo Copied %file_count% files to "%target_dir%"
pause

http://www.lryc.cn/news/612044.html

相关文章:

  • 互斥锁与条件变量
  • 自然语言处理基础—(1)
  • 深入理解 C++ 中的stdpriority_queue:从原理到实战的高效优先级管理
  • ssm复习
  • 【嵌入式电机控制#26】BLDC:三相模拟采集
  • springboot项目前后端通用下载方法、问题和解决方案
  • PyTorch生成式人工智能(26)——使用PyTorch构建GPT模型
  • AVDTP Media Packet 传输全流程解析:从 SDP 到连接终止
  • 基于AntDesign二次封装table组件
  • 思途AOP学习笔记 0806
  • nginx代理出https,request.getRequestURL()得到http问题解决
  • 界面规范的其他框架实现-列表-layui实现
  • TypeError: crypto$2.getRandomValues is not a function
  • 北大、蚂蚁三个维度解构高效隐私保护机器学习:前沿进展+发展方向
  • AlexNet训练和测试CIFAR10
  • Python金融分析:从基础到量化交易的完整指南
  • 如何定位一个高并发场景下API响应时间从200ms突增到2s的问题
  • 生成模型实战 | Transformer详解与实现
  • 需求链路追踪
  • centos配置java环境变量
  • SpringCloud -- elasticsearch(二)
  • MonoFusion 与 Genie 3
  • 如何快速掌握大数据技术?大四学生用Spark和Python构建直肠癌数据分析与可视化系统
  • Apollo中三种相机外参的可视化分析
  • 「iOS」————单例与代理
  • iOS 文件管理实战指南 查看 App 数据与系统日志的完整方法
  • Python虚拟环境完全指南:pyenv vs venv 在macOS上的使用详解
  • SpringBoot 3.x整合Elasticsearch:从零搭建高性能搜索服务
  • Post-train 入门(1):SFT / DPO / Online RL 概念理解和分类
  • 未给任务“Fody.WeavingTask”的必需参数“IntermediateDir”赋值。 WpfTreeView