Batch -"access is denied" 使用批处理访问文本文件时

Batch -"access is denied" when accessing a text file using batch

我在制作可以写入旧文本文件的批处理脚本时遇到了问题。当我尝试使用旧文本文件 运行 它说 "access is denied" (所以当我尝试将任何文本放入现有文件时)

无论如何这是代码:

@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 (带有 space)和值 b(带有 space)的变量。

删除 space 即可。