Results 1 to 14 of 14
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Understanding FSO (VBA/Word/2003 SP2)

    I have adapted the following code from here.
    <pre>Public Sub Main(MainPath As String)
    Dim fso, f, f1, fc, s, p
    Dim SearchPath As String
    Dim FoundFldr As String
    Dim FoundFldr2 As String
    Dim i As Long

    Set fso = CreateObject("Scripting.FileSystemObject")
    SearchPath = MainPath

    ReEntry1:
    Set f = fso.GetFolder(SearchPath)
    Set fc = f.SubFolders
    For Each f1 In fc
    s = f1.Path
    p = f1.parentfolder.Path
    Next
    If fc.Count > 0 Then
    SearchPath = s
    GoTo ReEntry1
    End If </pre>

    I have been unsuccessful in extracting the data associated with an individual folder (expecting to use something like fc(1).path ). So I have stuck with the inefficient For Next loop.

    Question 1 Is it possible to extract information from an individual item? How?

    Question 2 Is there a technique for making Intellisense available when coding in FSO? I'm certain that Hans has provided me with the answer to this in the past, but I cannot locate it. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    T.I.A.
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Question 2:
    - Set a reference (in Tools | References...) to Microsoft Scripting Runtime.
    - Change the declaration

    Dim fso, f, f1, fc, s, p

    to

    Dim fso As Scripting.FileSystemObject
    Dim f As Scripting.Folder
    Dim fc As Scripting.Folders
    Dim f1 As Scripting.Folder
    Dim s As String
    Dim p As String

    You'll now have IntelliSense available.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Question1: please explain what you want to accomplish.

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Thank you Hans.

    You have the patience of Job.
    Regards
    Don

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    <P ID="edit" class=small>(Edited by wdwells on 29-Jun-07 11:02. Typo corrected.)</P>I want to assign the path of any subfolder in the SearchPath to the variable 's'. With the current code, if there are 1000 subfolders, 's' is sequentially assigned the path of the each subfolder. If the path of item1 were assigned, the process would be much faster. This is the early stage of a process to delete a folder and all of its contents (including subfolders).
    Regards
    Don

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Understanding FSO (VBA/Word/2003 SP2)

    The DeleteFolder method of the FSO will delete a folder and its contents, including subfolders.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Thank you Rory
    Regards
    Don

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Understanding FSO (VBA/Word/2003 SP2)

    If you want to delete a folder and all it contains, you can use
    <code>
    Shell "cmd /c ""rd ""C:Folder1Folder2"" /s /q"""
    </code>
    rd is the 'remove directory' command; the /s switch specifies that you want to delete all subfolders and their contents too, and /q suppresses the prompt to confirm the deletion.

  9. #9
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Hi Rory
    I was having great success with this until I ran into a folder with a Read Only file therein. The Force argument doesn't seem to help.

    Any ideas that will make it unnecessary to scroll through all of the subfolders and reset the attributes of their files?

    T.I.A.
    Regards
    Don

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Off the top of my head, as it's late here, I suspect you may have to use Shell and the DOS <code>attrib -r *.* /s</code> function, but I will investigate further when I'm a bit more awake! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Thanks Rory
    I just read, incorporated and tested Hans' DOS code. to delete the package. It works a treat. Thanks again for your support..
    Regards
    Don

  12. #12
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Hello Hans

    Apologies for not responding sooner; I mistakenly thought that I had.

    Of course, your solution works a treat (Dear old DOS). Thank you. <img src=/S/salute.gif border=0 alt=salute width=15 height=20>

    Can you tell me what the "/c" switch accomplishes. I have misplaced my DOS reference manual.
    Regards
    Don

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Understanding FSO (VBA/Word/2003 SP2)

    See Command-line reference A-Z, more in particular Cmd. The description of the /c switch is
    <hr>/c : Carries out the command specified by string and then stops.<hr>
    Without the /c switch, the DOS window would remain open.

  14. #14
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Understanding FSO (VBA/Word/2003 SP2)

    Thank you for the response Hans; especially for the links.
    Regards
    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •