批处理基础(十四)在文件前插入内容

file_exist.bat文件内容如下:
注:del /f /q命令中,/f表示强制删除只读文件。/q表示安静模式,删除全域通配字符是,不要求确认。

@echo off
if "%1"=="" (
echo 命令用法:
echo %0 fileName
echo fileName 表示要插入内容的文件
echo.
echo 未指定要插入内容的文件,无法执行插入操作!
echo.
goto end
)

if not exist %1 (
echo 指定要插入的%1文件不存在,请仔细检查!
goto end
)

echo 正在进行插入操作......
echo.
echo %date% >> content.txt
echo %time% >> content.txt
copy content.txt + %1 temp.txt > nul
del /f /q %1 > nul
del /f /q content.txt > nul
ren temp.txt %1
echo 成功在%1文件前插入当前日期及时间!
:end

在这里插入图片描述

发布了228 篇原创文章 · 获赞 44 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_40945965/article/details/86757434