找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 27587|回复: 4

[文件操作] [分享]BAT脚本批量创建文件

[复制链接]
发表于 2019-7-23 16:20:56 | 显示全部楼层 |阅读模式
问题:
为何我这批处理不能  批量新建文件嗯
  1. @echo off
  2. Set i=0000
  3. :start
  4. @cd. >"c:\users\administrator\desktop\%i%.txt"
  5. if /a i<=0005(
  6. i=i+1
  7. got start
  8. )else exit
复制代码
方案1.bat
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "n=10000"
  4. for /l %%i in (%n%,1,10005) do (
  5.     set x=%%i
  6.     set x=!x:~-4!
  7.     cd.>"c:\users\administrator\desktop\!x!.txt"
  8. )
复制代码
方案2.bat
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "i=10000"
  4. :start
  5. cd.>"c:\users\administrator\desktop\!i:~-4!.txt"
  6. if !i! leq 10005 (
  7.     set /a i=i+1
  8.     goto :start
  9. )
复制代码
 楼主| 发表于 2019-7-23 20:01:32 | 显示全部楼层
问题:
能帮助 添加个 选择项吗, 输入txt新建txt,输入html 新建html,输入什么扩展名,新建什么扩展名的文件

方案1.bat
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "i=10000"
  4. REM 设置文件扩展名
  5. set "xxx=txt"
  6. :start
  7. cd.>"c:\users\administrator\desktop\!i:~-4!.%xxx%"
  8. if !i! leq 10005 (
  9.     set /a i=i+1
  10.     goto :start
  11. )
复制代码
方案2.bat
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "i=10000"
  4. REM 提示用户输入扩展名
  5. set /p "xxx=请输入文件扩展名:"
  6. :start
  7. cd.>"c:\users\administrator\desktop\!i:~-4!.%xxx%"
  8. if !i! leq 10005 (
  9.     set /a i=i+1
  10.     goto :start
  11. )
复制代码
 楼主| 发表于 2019-7-23 21:12:15 | 显示全部楼层
问题:
刚才已经建立0000.txt ,我又点击了bat批处理,结果新文件覆盖了之前的文件,如果  不想让它覆盖掉原文件,又该怎么处理呢

代码:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "i=10000"
  4. :start
  5. if not exist "c:\users\administrator\desktop\!i:~-4!.txt" (
  6.     cd.>"c:\users\administrator\desktop\!i:~-4!.txt"
  7. )
  8. if !i! leq 10005 (
  9.     set /a i=i+1
  10.     goto :start
  11. )
复制代码
发表于 2019-7-25 20:29:39 | 显示全部楼层
本帖最后由 impk 于 2019-7-25 20:45 编辑

问题:
为何我这批处理不能  批量新建文件嗯

@echo off
Set i=0000
:start
@cd. >"c:\users\administrator\desktop\%i%.txt"
if /a i<=0005(
i=i+1
got start
)else exit
  1. @echo off
  2. set i=1
  3. :start
  4. @echo test>"%cd%\%i%.txt"
  5. set /a i=%i%+1
  6. if %i% leq 5 (
  7. goto :start
  8. ) else goto :eof
复制代码
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set i=1
  4. :start
  5. cd.>"%cd%\!i!.txt"
  6. set /a i=%i%+1
  7. if !i! leq 5 (
  8. goto :start
  9. ) else goto :eof
复制代码
发表于 2019-7-25 20:53:40 | 显示全部楼层
本帖最后由 impk 于 2019-7-25 21:26 编辑

问题:
能帮助 添加个 选择项吗, 输入txt新建txt,输入html 新建html,输入什么扩展名,新建什么扩展名的文件

方案1.bat
@echo off
setlocal enabledelayedexpansion
set "i=10000"
REM 设置文件扩展名
set "xxx=txt"
:start
cd.>"c:\users\administrator\desktop\!i:~-4!.%xxx%"
if !i! leq 10005 (
    set /a i=i+1
    goto :start
)
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set i=1
  4. echo=
  5. echo=
  6. REM 设置文件扩展名
  7. set /p 扩展名=    请设置扩展名:
  8. :start
  9. cd.>"%cd%\!i!.%扩展名%"
  10. set /a i=!i!+1
  11. if !i! leq 5 (
  12. goto :start
  13. ) else goto :eof
复制代码
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set i=10000
  4. echo=
  5. echo=
  6. REM 设置文件扩展名
  7. set /p 扩展名=    请设置扩展名:
  8. :start
  9. cd.>"%cd%\!i:~-3!.%扩展名%"
  10. set /a i=!i!+1
  11. if !i! leq 10005 (
  12. goto :start
  13. ) else goto :eof
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 06:14 , Processed in 0.018301 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表