We help IT Professionals succeed at work.

batch file to make all sub-folders and their files writable

Hi, I'm not very good on writing batch files for Windows so please bear with me. What I want is a batch file which will make all sub-folders and their files writable.

The batch file would hold the paths to the directories I'd like to change. Something like:

c:\temp\folder1\
c:\temp\folder2\
c:\temp\folder3\subfolder1\
c:\temp\folder3\subfolder3\

Where I want folder1 and folder2 and all of their files and subfolders (and all of their folders and files, and so on) to be readable. And, for the next two, I'd only want subfolder1 and subfolder2 and all of their folders and files, and so on, to be readable. I wouldn't want c:\temp\folder3\subfolder2\ to be touched.

I know this sounds odd but this is how I need it to work. I have hundreds of files in hundreds of folders and instead of manually selecting the properties of each folder and changing the read\write check box it would be really nice to be able to just run a batch file. I know I can easily do this in Unix/Linux with chmod. I just don't know Windows scripting.

I'd like to be able to edit the batch file, add all of the directory paths that I need changed, save and close the file and run it. Maybe have it so that it doesn't dump out all of the files that are being updated.

Anyway, if anyone can help out, I'd appreciate it.

Thanks,
biglarrrr
Comment
Watch Question

I'm not sure whether you want Read-Only attribute or Read permission
For read-permission for a particular user:
http://technet.microsoft.com/en-us/library/bb490872.aspx

For setting read-only attribute:
http://www.computerhope.com/attribhl.htm
Hi there, try this

@echo off
attrib /s /d c:\temp\folder1\* +r
attrib /s /d c:\temp\folder1\* +r
attrib /s /d c:\temp\folder3\subfolder1\* +r
attrib /s /d c:\temp\folder3\subfolder2\* +r
exit

Open in new window

Author

Commented:
Hi, mgh_mgharish and romel_rms, thanks for replying!

I want to be able to write to the files. Meaning, I don't want the files to be read-only (eg chmod 777).

romel_rms, I tried what you sent and it looks like that sets everything to read-only. I'm assuming that the /s is for read-only and the +r means to touch anything and everything within the given directory?

Thanks,
biglarrrr
OK, Then what you need is the reverse of romel_rms's script..

attrib /s /d c:\temp\folder1\* -r
attrib /s /d c:\temp\folder1\* -r
attrib /s /d c:\temp\folder3\subfolder1\* -r
attrib /s /d c:\temp\folder3\subfolder2\* -r

The second link given by me gives details about the command..
No +r = read only /s sub folders
and if you want to reverse it, make it as mgh_mgharish posted be4 this post

start > run > cmd press enter
attrib /?

then see what is attrib parameters, it helps you
Steven CarnahanAssistant Vice President\Network Manager

Commented:
The second part of the question is to be able to edit the folders you want to change. Since you said you have hundreds you may want to consider running a dir command to a text file:

dir /a:d /b /s > listing.txt

This will list all the directories from the present directory including all sub directories and place them in a file called listing.txt

You then can either use cut and paste to edit what romel has given you or you can add some logic to read the directory names from the file.

Author

Commented:
Thanks mgh_mgharish and romel_rms!

That http://www.computerhope.com/attribhl.htm page is great! I'd like to split the point for this one. Thanks for your help!