跳至内容
bat文件实验

bat文件实验

自动git提交

.bat文件准备

  1. 新建txt,写入一下内容
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
@echo off
REM 切换到 仓库所在目录
cd /d "D:\github_blog\"

REM 执行 Git 命令
git add .
git commit -m "update"
git push

REM 响应一下啦!
echo gooo_job!
pause
  1. 另存为“所有文件(*)”,编码类型选择ANSI,命名为auto_git_commit.bat,放在如 D:/script 下。

  2. 注意事项

    • cd \d “D:/” 一定要有双引号,否则找不到。

    • 如何记住哪个是转义字符的斜杠,哪个是目录的斜杠 tips: \n\t已记住,所以\是转义,所以/是目录的

    • 命名文件夹、文件 不要有 空格 或 . . 开头会导致以为是 ‌**“点文件”(Dot Files)(隐藏文件)**如.bat

    • echo 后面的内容不要有空格,要连续

    • 编码格式要为ANSI,utf-8不行

任务计划程序内创建基本任务

  1. win+r 输入指令 taskschd.msc 任务计划程序(Task Scheduler —— taskschd)

    打开(O):taskschd.msc

  2. 最右侧一栏 找到 创建基本任务

    • 输入名称、描述

    • 希望该任务何时开始? —— 每天(D)

    • 填1,每隔1天发生一次

    • 希望该任务执行什么操作? —— 启动程序(T)

    • 程序或脚本(P): —— 点击浏览(R),找到auto_git_commit.bat,如在 D:/script 下。

    • 完成

创建新blog的 .bat文件

除了内容,其他和前者创建.bat文件一样

用到hugo框架,故用hugo new content创建目录、文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@echo off
setlocal enabledelayedexpansion

:input_blog_name
cls
echo 请输入博客名称(不含空格,不要 . 开头):
set /p "blog_name=>> "

REM 检查输入是否为空
if "%blog_name%"=="" (
    echo 错误:博客名称不能为空!
    timeout /t 2 /nobreak >nul
    goto input_blog_name
)

REM 执行操作
cd /d "D:\github_blog\"
hugo new content post/%blog_name%/index.md

REM 结果反馈
if exist "D:\github_blog\" (
    echo D:\github_blog\content\post\%blog_name%\index.md 现已存在
) 

pause
最后更新于