Results 1 to 7 of 7

Thread: FileSystemObject

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    1

    FileSystemObject

    how to move and file folders and subfolders with all the files to another folder, checking whether there are more files in subfolders, recalling that in the first folder may have folder and files together, how do I not make any mistake when the two?

    thanks

  2. #2
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    269

    Re: FileSystemObject

    Have a search for "recursive dir" there are examples on here to get you nearly all the way with your problem pal.

  3. #3
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: FileSystemObject

    No recursion needed; just use API:
    Code:
    ' Constants for API calls
    Private Const FOF_MULTIDESTFILES As Long = &H1
    Private Const FOF_CONFIRMMOUSE As Long = &H2
    Private Const FOF_SILENT As Long = &H4
    Private Const FOF_RENAMEONCOLLISION As Long = &H8
    Private Const FOF_NOCONFIRMATION As Long = &H10
    Private Const FOF_WANTMAPPINGHANDLE As Long = &H20
    Private Const FOF_CREATEPROGRESSDLG As Long = &H0
    Private Const FOF_ALLOWUNDO As Long = &H40
    Private Const FOF_FILESONLY As Long = &H80
    Private Const FOF_SIMPLEPROGRESS As Long = &H100
    Private Const FOF_NOCONFIRMMKDIR As Long = &H200
    
    Private Const MAX_PATH = 260
    Private Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR
    Private Const FILE_FLAGS_SILENT = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR Or FOF_SILENT
    
    Private Type SHFILEOPSTRUCT
        hwnd As Long
        wFunc As Long
        pFrom As String
        pTo As String
        fFlags As Long
        fAnyOperationsAborted As Long
        hNameMappings As Long
        lpszProgressTitle As String
    End Type
    
    Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    
    Public Function MoveFolder(pstrSource As String, pstrDest As String) As Long
        Const FO_MOVE As Long = &H1
        Dim typFO As SHFILEOPSTRUCT
        
        With typFO
            .wFunc = FO_MOVE
            .fFlags = FILE_FLAGS
            .pFrom = pstrSource & vbNullChar & vbNullChar
            .pTo = pstrDest & vbNullChar & vbNullChar
        End With
        MoveFolder = SHFileOperation(typFO)
    End Sub
    This will move entire folder trees in one shot. Sample usage:

    MoveFolder "C:\Temp", "C:\New"

  4. #4
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    269

    Re: FileSystemObject

    Me likey. I must stop being afraid of APIs Cheers ED.

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: FileSystemObject

    Quote Originally Posted by Moorzee
    Me likey. I must stop being afraid of APIs Cheers ED.
    There is a set of wrapper classes in my signature that expose many frequently used API calls in an easy to use manner. It has a bit of overhead, and adding 5 classes to a project definitely adds some clutter, but it really does make things a lot easier in general.

    This MoveFolder technique is in there, along with Copy and Delete. Plus fully-featured registry manipulation, etc...

    All without you having to even look at an API call. Even if you don't use them as-is, they are functional code examples you can chop up as needed.

  6. #6
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    269

    Re: FileSystemObject

    Sorry for thread hijack. Looking into API stuff E.D How do you ascertain what constants are required for any API function/call?

    For instance the CopyFileA API call has a bFailIfExists param that I assume must be a const somewhere???????

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: FileSystemObject

    Quote Originally Posted by Moorzee
    Sorry for thread hijack. Looking into API stuff E.D How do you ascertain what constants are required for any API function/call?

    For instance the CopyFileA API call has a bFailIfExists param that I assume must be a const somewhere???????
    You'll want the Platform SDK which includes the C header files for Windows APIs.

    For example at CopyFile Function it tells you:
    Header Declared in WinBase.h; include Windows.h.
    So you look in those header files.

    In many cases the VB6 API Viewer or a 3rd party alternative can be used. Of course the databases these come with are often incomplete and out of date, but this can be a good place to look first.


    Many of the entrypoints in Shell32.dll will not work in certain application contexts since they require a Windows Shell (desktop). For example a Windows Service may require "Interact with desktop" to be configured, and this can be problematic in Vista or in a Terminal Server environment where services don't normally have access to a WinStation with a live Desktop. The same issues can arise in any recent Windows OS when nobody is logged on at the console.

Posting Permissions

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



Click Here to Expand Forum to Full Width