convert a file attribute to "read only"

The below script works great, however I find a problem that needs to be resolved, either in this script or from a separate one.  

The file being copied "keycode", I need to convert it to "read only" attribute using batch.  
It does not matter to me before the copy...or after.  

echo.
echo.
IF EXIST dir_search.txt del /q /f dir_search.txt
FOR %%i in (C D E) do @dir %%i:\*bquest /s /b /ad>> dir_search.txt
FOR /F "tokens=* delims=" %%x in (dir_search.txt) do if not exist "%%x\keycode" copy /v /y etkey "%%x\keycode"
cls
exit


Thanks in advance
icecom4Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tony BarkdullTier 2 SupportCommented:
Just add the line
attrib *dir\keycode.* +r

where *dir is the target folder
0
Paul TomasiCommented:
Try this...

@echo off

echo.
echo.

(for %%i in (C D E) do (dir %%i:\*bquest /s /b /ad))>dir_search.txt

for /f "tokens=* delims=" %%x in (dir_search.txt) do (
  if not exist "%%x\keycode" (
    copy /v /y etkey "%%x\keycode"
    attrib +r "%%x\keycode"
  )
)

cls
exit

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul TomasiCommented:
Or this... If line 6 in the previous code gives you problems.

You may change Line 6 (in the following code) back to as it was in your original code if you so wish to however, it should work fine just as it is.

@echo off

echo.
echo.

del /q /f dir_search.txt 2>nul

for %%i in (C D E) do dir %%i:\*bquest /s /b /ad>>dir_search.txt

for /f "tokens=* delims=" %%x in (dir_search.txt) do (
  if not exist "%%x\keycode" (
    copy /v /y etkey "%%x\keycode"
    attrib +r "%%x\keycode"
  )
)

cls
exit

Open in new window

0
icecom4Author Commented:
Thank you!!!
0
Paul TomasiCommented:
Oh, to supress out from the COPY command, you may change Line 12 to:

    copy /v /y etkey "%%x\keycode" >nul

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.