"拒绝访问"对于文本文件错误消息,我只是做了? [英] "access denied" error message for a text file i just made?

查看:124
本文介绍了"拒绝访问"对于文本文件错误消息,我只是做了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约3天前,我问了一个问题,它可以在这里找到:

<一个href=\"http://stackoverflow.com/questions/4310472/how-to-replace-a-string-on-the-second-line-in-a-text-file-using-a-batch-file\">how使用批处理文件来替换在一个文本文件中的第二行的字符串?

我转换的字母在一个文本文件到各自的数字。我收到错误消息,例如拒绝访问和无法找到该文件 - 但是这给了我所有这些错误的同一批文件,也是使这些文本文件,从而开始与一个!因此,它应该是在同一目录中的批处理文件本身(除非另有规定),对不对?我还跟到该文件夹​​和检查,他们在那里。

我添加了小脚本来隐藏文件,它们被创建后,这样就不会显得那么凌乱了。我用这样做。

  ATTRIB + H C:\\脚本\\%名称%.TXT

在它

应该隐藏与此命令文件,使其不可见正在寻找它的批处理程序/调用?

下面是该文件,stringparsing.bat的链接:的http://上传。 COM /文件/ a1m1d2f4 / stringparsing.bat /

如果你能帮助我得到这个程序执行其任务,没有任何错误,这将大大AP preciated!

下面是完整的stringparsing.bat文件:

 关闭@echo
SETLOCAL enabledelayedexpansion
标题BETA
CLS
CD C:\\脚本\\ ST
回声。
回声。
回声。
呼应设置变量...
回声加载语言数据库...:: ################################################ ###################################
::呼唤变量DATABASE CALLING变量DATABASE CALLING变量DATABASE
:: ################################################ ###################################
TIMEOUT /吨5 / NOBREAK&GT; NUL转到主:主要
集富= 0
CLS
回声。
回声。
回声。
回声。
回声===================================
回声#################################
呼应#######主菜单:#######
回声#################################
回声===================================
回声。
回声。
1.呼应)创建新的语言文件...
回声。
2.呼应)加载现有Lanuage文件...
回声。
3.呼应)设置...回声------------------------------------------------- --------SET / p = CHOICE选择一个功能:
IF%CHOICE%== 1 GOTO CREATE
IF%CHOICE%== 2 GOTO LOAD
IF%CHOICE%== 3 GOTO设置GOTO MAIN:创建
CLS
标题第1步
回声。
回声。
回声。
回声================================================= ================================
回声。
集/ p NAME =,请为您的新的语言文件的名称:
回声。
回声================================================= ================================
CLS
回声。 &GT; %名称%.TXT
回声。
回声。
回声。
回声================================================= =============
回声################################################# #############
回声#================================================ ============#
回声##
回声# - 你打后,输入您将被重定向#
回声#到现场打字员。所以,只要你键入#
回声#它将被送到%名称%.txt中。 #
回声##
回声##
回声# - 下一步,选择装载语言文件进行编码! #
回声##
回声#================================================ ============#
回声################################################# #############
回声================================================= =============集/ p = 1行:
回声%行1%GT;&GT; %名称%.TXT 2 - ; NUL
回声%名称%&GT; Language_File.txt
ATTRIB + H Language_File.txt
集/一个Foo + = 1

回声。
回声================================================= =========转到LOAD:加载
集/一个Foo + = 1
IF%富%== 2转到loadexternal
转到LOAD23:loadexternal
回声。
现在回声语言文件加载!
设置/ p名=&LT; Language_File.txt
超时/吨4 / NOBREAK&GT; NUL
回声。
回声。
回声Language_File装!
暂停&GT; NUL
转到LOAD23:LOAD23
CLS
回声。
回声。
回声。
回声。
回声。
回声编码你的语言文件,请稍候...
回声。
回声。
回声。FOR / Fdelims =%% i的(!名字!.txt)中做(
回声翻译%%我
组VAR = %%我
组VAR = VAR:A = 1!
组VAR = VAR:B = 2!
组VAR = VAR:C = 3!
组VAR = VAR!:D = 4!
组VAR = VAR:E = 5!
组VAR = VAR:F = 6!
组VAR = VAR:G = 7!
组VAR = VAR:H = 8!
组VAR = VAR:I = 9!
组VAR = VAR:J = 10!
组VAR = VAR:K = 11!
组VAR = VAR:L = 12!
组VAR = VAR:M = 13!
!一套VAR = VAR:N = 14!
组VAR = VAR:O = 15!
组VAR = VAR:P = 16!
组VAR = VAR:Q = 17!
组VAR = VAR:R = 18!
组VAR = VAR:S = 19!
组VAR = VAR:T = 20!
组VAR = VAR:U = 21!
组VAR = VAR:V = 22!
组VAR = VAR:W = 23!
组VAR = VAR:X = 24!
组VAR = VAR:Y = 25!
组VAR = VAR:Z = 26!回音!VAR!
)回音!VAR! &GT; !名字!.TXT暂停&GT; NUL
TIMEOUT /吨5 / NOBREAK&GT; NUL转到主
:结束
CLS
标题关停...
回声。
回声。
回声。
呼应终止业务流...
回声。
回声。
回声。
回声。
回声完成!感谢您使用这个程序!
TIMEOUT /吨5 / NOBREAK&GT; NUL::(%XX%)-1 I / O流=SHELL.DLL
::如果有[&放大器; 1 [Parser_2009]退出出口
:: ################################################ #####################################


解决方案

您已经有了一些问题。首先,访问被拒绝的问题是你重定向到一个隐藏的文件。

 回声%名称%&GT; Language_File.txt
ATTRIB + H Language_File.txt

请注意,您运行脚本的第一次,它会工作,因为Language_File.txt将不存在,因此不会被隐藏。你运行它的第二次,你会得到拒绝访问。我不知道为什么Windows不会让你这样做。您可以通过几种方法解决这个问题。

1 您的文件保存到用户的临时目录。通过这种方法目录不会得到杂乱。

 回声%名称%&GT; %TMP%\\ Language_File.txt

2 您的文件保存到你自己的,这样不会弄乱脚本的目录中的子目录。

 如果不存在工作区工作区的mkdir
回声%名称%&GT;工作区\\ Language_File.txt

3。取消隐藏在使用它之前的文件。由于该文件可能不存在你第一次运行该脚本,也许你应该只 ATTRIB -h (如果存在)。

 是否存在Language_File.txt ATTRIB -h Language_File.txt
回声%名称%&GT; %TMP%\\ Language_File.txt
ATTRIB + H Language_File.txt

4。不要使用Language_File.txt了!我不明白为什么你需要它。只需使用变量来保存语言文件的名称。事实上,你已经在%名称%名称,对吧?

其次,你应该检查你的变量的值,看看他们真正持有。当你Language_File.txt的内容加载到您的变量,它加载所有的内容。这包括隐藏的换行符 \\ r \\ n ,虽然剧本似乎把他们带入变量空间。参见:

  C:\\批次\\ T&GT;回声语言文件中现在载入!
现在语言文件加载
C:\\批次\\ T&GT;设置/ p名=&LT; Language_File.txt
C:\\批次\\ T&GT;回声 - %名称% -
-langfile -

如果您回声%名称%用连字符包围,你可以看到有后2位从(presumably)的换行符。为了解决这个问题,你可以使用一套修剪尾随字符。

  C:\\批次\\ T&GT;回声语言文件中现在载入!
现在语言文件加载
C:\\批次\\ T&GT;设置/ p名=&LT; Language_File.txt
C:\\批次\\ T&GT;设置名称=%名称:〜0,-2%
C:\\批次\\ T&GT;回声 - %名称% -
-langfile-

在第二个例子中,`%名称%没有隐藏人物。

最后,你只需要使用来访问您在循环设置变量。因此,要!名称的所有引用!%名称%来代替。这可能是你的找不到文件的错误。

About 3 days ago I asked a question, which can be found here:

how to replace a string on the second line in a text file using a batch file?

I'm converting the letters in a text file into their respective numbers. I'm getting error messages such as "Access denied" and "Cannot locate this file" -- but the same batch file that's giving me all these errors is also the one that made these text files to begin with! So it should be in the same directory as the batch file itself (unless specified otherwise), right? I even went to that folder and checked, and they're there.

I did add a small script to hide the files after they were created so that it wouldn't look so cluttered up. I did this by using

attrib +h C:\script\%name%.txt

Would hiding a file with this command make it invisible to batch programs that are searching for it/call upon it?

Here's a link to the file, "stringparsing.bat": http://uploading.com/files/a1m1d2f4/stringparsing.bat/

If you could assist me in getting this program to carry out its task without any errors it would be greatly appreciated!

Here's the "stringparsing.bat" file in full:

@echo off
setlocal enabledelayedexpansion 
title BETA
cls
cd C:\script\st
echo.
echo.
echo.
echo      Setting Variables...
echo      Loading Language Database...

:: ###################################################################################
::    CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################




TIMEOUT /t 5 /nobreak > nul

goto MAIN

:MAIN
set foo=0
cls
echo.
echo.
echo.
echo.
echo            ===================================
echo             #################################        
echo             #######     Main Menu:    #######
echo             #################################
echo            ===================================
echo.
echo.
echo             1.) Create New Language File...
echo.
echo             2.) Load Existing Lanuage File...
echo.
echo             3.) Settings...

echo ---------------------------------------------------------

SET /p CHOICE= Select a Function:
IF %CHOICE%== 1 GOTO CREATE
IF %CHOICE%== 2 GOTO LOAD
IF %CHOICE%== 3 GOTO SETTINGS

GOTO MAIN

:CREATE
cls
title Step 1
echo.
echo.
echo.
echo         =================================================================================
echo.
set /p name=  please type a name for your new language file:
echo.
echo         =================================================================================
cls
echo. > %name%.txt
echo.
echo.
echo.
echo        ==============================================================
echo        ##############################################################
echo        #============================================================#
echo        #                                                            #
echo        # - After you hit enter you will be redirected               #
echo        #   to a Live Typer. so anything you type into               #
echo        #   it will be sent to %name%.txt.                           #
echo        #                                                            #
echo        #                                                            #
echo        # - Next, select load language File For Encoding!            #
echo        #                                                            #
echo        #============================================================#
echo        ##############################################################
echo        ==============================================================

set /p line1= :
echo %line1% >> %name%.txt 2> nul


echo %name% > Language_File.txt
attrib +h Language_File.txt
set /a foo+ =1
)
echo.
echo ==========================================================

goto LOAD



:LOAD
set /a foo+ =1
IF %foo%== 2 goto loadexternal
goto LOAD23

:loadexternal
echo.
echo language file is loading now!
set /p name=<Language_File.txt
timeout /t 4 /nobreak > nul
echo.
echo.
echo Language_File Loaded!
pause >nul
goto LOAD23

:LOAD23
cls
echo.
echo.
echo.
echo.
echo.
echo        Encoding Your Language File... Please Wait... 
echo.
echo.
echo.

for /f "delims=" %%i in (!name!.txt) do ( 
echo translating "%%i"
set var=%%i 
set var=!var:a=1 ! 
set var=!var:b=2 ! 
set var=!var:c=3 ! 
set var=!var:d=4 ! 
set var=!var:e=5 ! 
set var=!var:f=6 ! 
set var=!var:g=7 ! 
set var=!var:h=8 ! 
set var=!var:i=9 ! 
set var=!var:j=10 ! 
set var=!var:k=11 ! 
set var=!var:l=12 ! 
set var=!var:m=13 ! 
set var=!var:n=14 ! 
set var=!var:o=15 ! 
set var=!var:p=16 ! 
set var=!var:q=17 ! 
set var=!var:r=18 ! 
set var=!var:s=19 ! 
set var=!var:t=20 ! 
set var=!var:u=21 ! 
set var=!var:v=22 ! 
set var=!var:w=23 ! 
set var=!var:x=24 ! 
set var=!var:y=25 ! 
set var=!var:z=26 ! 

echo !var! 
) 

echo !var! > !name!.txt

pause >nul
TIMEOUT /t 5 /nobreak > nul

goto MAIN


:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo            Terminating service stream...
echo.
echo.
echo.
echo.
echo            Done! Thank you for using this program!
TIMEOUT /t 5 /nobreak > nul





::(%xx%) -1  I/O Stream= "SHELL.dll" 
:: IF EXIST [&1[Parser_2009]] exit

Exit


:: #####################################################################################

解决方案

You've got a few problems. First, the access denied problem is from you redirecting to a hidden file.

echo %name% > Language_File.txt
attrib +h Language_File.txt

Note that the first time you run the script, it will work because Language_File.txt won't exist and therefore won't be hidden. The second time you run it, you'll get access denied. I don't know why Windows doesn't let you do that. You can solve this problem in a couple ways.

1. Save your file to the user's temp directory. With this approach your directory won't get cluttered.

echo %name% > %TMP%\Language_File.txt

2. Save your file to a subdirectory that you own so that it doesn't clutter the script's directory.

if not exist workspace mkdir workspace
echo %name% > workspace\Language_File.txt

3. Unhide the file before you use it. Since the file may not exist the first time you run the script, perhaps you should only attrib -h if it exists.

if exist Language_File.txt attrib -h Language_File.txt
echo %name% > %TMP%\Language_File.txt
attrib +h Language_File.txt

4. Don't use Language_File.txt at all! I don't see why you need it. Just use variables to hold the name of the language file. In fact, you already have the name in %name%, right?

Second, you should check the value of your variables to see what they really hold. When you load the contents of Language_File.txt into your variable, it's loading all the contents. That includes the hidden newline characters \r\n, although the script seems to bring them into the variable as spaces. See:

c:\batch\t>echo language file is loading now!
language file is loading now
C:\batch\t>set /p name= <Language_File.txt
C:\batch\t>echo -%name%-
-langfile  -

If you echo %name% surrounded by hyphens, you can see that there are 2 spaces after it from (presumably) the newline characters. To solve this problem, you can use set to trim the trailing characters.

C:\batch\t>echo language file is loading now!
language file is loading now
C:\batch\t>set /p name= <Language_File.txt
C:\batch\t>set name=%name:~0,-2%
C:\batch\t>echo -%name%-
-langfile-

In the second example, `%name% doesn't have the hidden characters.

Finally, you only need to use ! to access variables that you set inside the for loop. So all references to !name! should be %name% instead. That's probably your "cannot find file" error.

这篇关于&QUOT;拒绝访问&QUOT;对于文本文件错误消息,我只是做了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆