【发布时间】:2017-08-06 11:34:11
【问题描述】:
我在制作可以写入旧文本文件的批处理脚本时遇到问题。当我尝试使用旧文本文件运行它时,它说“访问被拒绝”(所以当我尝试将任何文本放入现有文件时)
这里是代码:
@echo off
title file editor/creator
set lineNR=0
:start
set /p ANS= Do you want to access a 1:"old file" or 2"create a new" [1/2]
if %ANS% EQU 1 ( goto old
) ELSE if %ANS% EQU 2 ( goto new
) ElSE ( echo invalid input & goto start)
:old
set /p name = what is the name of the file
set /p ending = what type of file is it
goto loop
:new
set /p name= what do you want the name of the file to be
set /p ending= what type of file do you want the file to be
echo %name%.%ending%
:Q1
set /p echo_off= do you want echo to be off? [y/n]
if %echo_off% EQU y (
echo @echo off >%name%.%ending%
goto loop
) ELSE IF %echo_off% EQU n (
goto loop
) ELSE (
goto Q1
)
:loop
echo press CTRL+LSHIF+C to end loop
goto loop1
:loop1
set /a lineNR=%lineNR% + 1
set /p line= %lineNR%:
echo %line% >>%name%.%ending%
// this is where it says that access is denied
goto loop1
【问题讨论】:
-
set a = b生成一个名为a(注意空格!)的变量,其值为 `b`(注意空格!)。删除等号之间的空格 -
另请参阅this MS support 了解有关您的问题的更多信息
-
感谢这项工作;3
标签: batch-file editing