• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

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
0
icecom4
Asked:
icecom4
  • 3
1 Solution
 
Tony BarkdullCommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now