cmd - "access denied" error message for a text file i just made? -
about 3 days ago asked question, can found here:
how replace string on second line in text file using batch file?
i'm converting letters in text file respective numbers. i'm getting error messages such "access denied" , "cannot locate file" -- same batch file that's giving me these errors 1 made these text files begin with! should in same directory batch file (unless specified otherwise), right? went folder , checked, , they're there.
i did add small script hide files after created wouldn't cluttered up. did using
attrib +h c:\script\%name%.txt would hiding file command make invisible batch programs searching it/call upon it?
here's link file, "stringparsing.bat": http://uploading.com/files/a1m1d2f4/stringparsing.bat/
if assist me in getting program carry out task without errors appreciated!
here's "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 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 name new language file: echo. echo ================================================================================= cls echo. > %name%.txt echo. echo. echo. echo ============================================================== echo ############################################################## echo #============================================================# echo # # echo # - after hit enter redirected # echo # live typer. type # echo # sent %name%.txt. # echo # # echo # # echo # - next, select load language file 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 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 language file... please wait... echo. echo. echo. /f "delims=" %%i in (!name!.txt) ( 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 using program! timeout /t 5 /nobreak > nul ::(%xx%) -1 i/o stream= "shell.dll" :: if exist [&1[parser_2009]] exit exit :: #####################################################################################
you've got few problems. first, access denied problem redirecting hidden file.
echo %name% > language_file.txt attrib +h language_file.txt note first time run script, work because language_file.txt won't exist , therefore won't hidden. second time run it, you'll access denied. don't know why windows doesn't let that. can solve problem in couple ways.
1. save file user's temp directory. approach directory won't cluttered.
echo %name% > %tmp%\language_file.txt 2. save file subdirectory own doesn't clutter script's directory.
if not exist workspace mkdir workspace echo %name% > workspace\language_file.txt 3. unhide file before use it. since file may not exist first time run script, perhaps should attrib -h if 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 @ all! don't see why need it. use variables hold name of language file. in fact, have name in %name%, right?
second, should check value of variables see hold. when load contents of language_file.txt variable, it's loading contents. includes hidden newline characters \r\n, although script seems bring them variable spaces. see:
c:\batch\t>echo language file loading now! language file loading c:\batch\t>set /p name= <language_file.txt c:\batch\t>echo -%name%- -langfile - if echo %name% surrounded hyphens, can see there 2 spaces after (presumably) newline characters. solve problem, can use set trim trailing characters.
c:\batch\t>echo language file loading now! language file loading c:\batch\t>set /p name= <language_file.txt c:\batch\t>set name=%name:~0,-2% c:\batch\t>echo -%name%- -langfile- in second example, `%name% doesn't have hidden characters.
finally, need use ! access variables set inside for loop. references !name! should %name% instead. that's "cannot find file" error.
Comments
Post a Comment