Board logo

标题: [文件操作] [分享]BAT脚本批量创建文件 [打印本页]

作者: Batcher    时间: 2019-7-23 16:20     标题: [分享]BAT脚本批量创建文件

问题:
为何我这批处理不能  批量新建文件嗯
  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. )
复制代码

作者: Batcher    时间: 2019-7-23 20:01

问题:
能帮助 添加个 选择项吗, 输入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. )
复制代码

作者: Batcher    时间: 2019-7-23 21:12

问题:
刚才已经建立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. )
复制代码

作者: impk    时间: 2019-7-25 20:29

本帖最后由 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
复制代码

作者: impk    时间: 2019-7-25 20:53

本帖最后由 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
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2