API - set group of files to ReadOnly

Discussion in 'SolidWorks' started by Wayne Tiffany, Jul 5, 2005.

  1. 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
     
    Wayne Tiffany, Jul 5, 2005
    #1
  2. Wayne Tiffany

    Tom Guest

    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
     
    Tom, Jul 5, 2005
    #2
  3. Wayne Tiffany

    POH Guest

    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
    ________________________________________________
     
    POH, Jul 5, 2005
    #3
  4. Wayne Tiffany

    Tom Guest

    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
     
    Tom, Jul 5, 2005
    #4
  5. Wayne Tiffany

    SWX-VAR-JP Guest

    SWX-VAR-JP, Jul 5, 2005
    #5
  6. Wayne Tiffany

    Seth Renigar Guest

    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.
     
    Seth Renigar, Jul 6, 2005
    #6
  7. Wayne Tiffany

    Jean Marc Guest

    Good one !!!
     
    Jean Marc, Jul 6, 2005
    #7
  8. 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
     
    Wayne Tiffany, Jul 6, 2005
    #8
  9. Ahhh, teach a man to fish..... :)

    WT

     
    Wayne Tiffany, Jul 6, 2005
    #9
  10. Wayne Tiffany

    CS Guest

    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.
     
    CS, Jul 6, 2005
    #10
  11. 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
     
    Wayne Tiffany, Jul 6, 2005
    #11
  12. Wayne Tiffany

    CS Guest

    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
     
    CS, Jul 8, 2005
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.