API - set group of files to ReadOnly

I am working on a program in which, after I move a bunch of files to a location, I would like to set all the files in that folder to ReadOnly. I have set that attribute before, but only on 1 specific, known file. Has anyone done it on a whole folder?

WT

Reply to
Wayne Tiffany
Loading thread data ...

Wayne:

I'd do it with a command window. You have to be able to navigate to the directory with the files that are to be read-only. Then the syntax is "attrib +r *.*" (without the quotes)

MS is trying to get this kind of stuff to go away, though. You may be able to do it with a dialog box. In an explorer window, select all the files (CTRL-A) then right click, select Properties, tick the read-only box.. It should work.

Take it easy,

Tom

Reply to
Tom

Highlight the desired folder (in the Windows Explorer pane) and right click to access "properties" in the pull-down menu. Then check the "Read Only" attribute. When "OK" is clicked, a dialog box will appear to ask whether just the folder itself or the folder, sub-folders and all contents should be given the attribute.

Per O. Hoel ________________________________________________

Tom wrote:

Reply to
POH

Whoops, I screwed up. You're talking about API programmming. Sorry.

I've never used the VB stuff with SW yet, but you may be able to send such a command to the operating system...

Tom

Reply to
Tom

You will need to use the FileSystemObject to access these attributes. You can also use this to find all the file names of all files within a folder.

Here is a link to a good writeup on the FSO

formatting link
Here is an example of recursive searching that uses a form, but you could easily loose the form perform the change with code
formatting link
.

Reply to
SWX-VAR-JP

Tom,

Also from the Explorer window I have found a "quick" way to do it (at least in WinXP). Once the desired files are highlighted, from the keyboard press: Alt-Enter, Spacebar, Enter.

I am a big keyboard fan. Using the mouse is usually slower than keyboard commands, for me anyway.

Reply to
Seth Renigar

"Seth Renigar" a écrit dans le message de news:NFPye.127700$ snipped-for-privacy@twister.southeast.rr.com...

Good one !!!

Reply to
Jean Marc

Thanks for the links. I was hoping for something as simple as the one-liner to set one file to read-only, but I guess it will take a bit more studying.

WT

Reply to
Wayne Tiffany

Ahhh, teach a man to fish..... :-)

WT

"Seth Renigar" wrote in message news:NFPye.127700$ snipped-for-privacy@twister.southeast.rr.com...

Reply to
Wayne Tiffany

Wayne it is pretty easy using the FileSystemObject

Early binding if you reference "Microsoft Scripting Runtime"

Dim FSystem As FileSystemObject Dim ProducionDwgs As Folder Dim d As Scripting.File

Set FSystem = New FileSystemObject Set d = FSystem.GetFile(PathToFile) d.Attributes = ReadOnly

you can loop the files in a folder like this

set ThisFolder = FSystem.GetFolder

for each d in ThisFolder.files d.Attributes = ReadOnly next

You might want to throw in if statements to check existence

If Filesystem.FileExists(PathToFile) Then or If Filesystem.FolderExists(PathToFolder) Then

I have been using this and it is wonderful.

Reply to
CS

Looking at what you just wrote makes it look not too difficult if you are already used to using objects, obviously. I haven't had the chance to do any reading yet (real work gets in the way...) but it certainly looks doable. Thanks.

WT

Reply to
Wayne Tiffany

Yeah the bigest problem I had at first was knowing which dll to add to the references for early binding. Once you have the reference added it is pretty strait foreward. Anthony Noll replied to my personal e-mail instead of the group I presume he intended it to end up here

"Don't forget to include the full path in the GetFolder method, i.e. Set ThisFolder = FileSysObj.GetFolder(FoldrPath) Good luck Tony"

I see in haste i missed the folder path for getFolder.

Good luck getting past the "Real Work" it is funny how setting up to be efficient in the software world isn't concidered "Real Work" in a manufacturing job you would get a pat on the back maybe even a raise.

Corey

Reply to
CS

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.