Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    ASP Move file from all folders...

    I have the following folder with images in, these images get moved to where I want them no problem: E:/DCIM

    I now need to adapt the code to move all the images from sub-folders within the folder above, how do I do that?

    Example:
    E:/DCIM/PJ87668
    E:/DCIM/PJ66382

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,618
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    CopyFolder will do it all for you in one operation:

    Code:
    fromFolderName = "E:"
    toFolderName = "C:\someplace\saveimages" 
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    ' copy all files and folders:
    Call FSO.CopyFolder( fromFolderName & "\*", toFolderName & "\", overwriteflag )
    Notice that you need the \* on the end of the FROM and the \ on the end of the TO.

    If the last argument is true, CopyFolder will overwrite any existing files and folders. To avoid that, be sure to use FALSE (false in JS code) instead.


    Do you not have a copy of the Microsoft Scripting Help file on your machine? If not, you *REALLY* need to download it. MS keeps moving it from time to time, but at least as of today it is here:
    http://www.microsoft.com/en-us/downl...s.aspx?id=2764

    Download it! Make a link to it on your desktop. Use it every day.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-12-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    I don't want the folders you see, just all the files from within them. Just though of this.

    Code:
    path = drive&":\DCIM\"
    set folder = fs.GetFolder(path)
    paths = ""
    
    for each item in folder.SubFolder
            paths = paths & "," & item.name
    next
    
    currentPath = split(paths, ",")
    
    for each p in currentPath
           fs.MoveFile path&"\"&p, location
    next
    (along them lines, not tested the above)

    Just search the sub folders and put them all into one string, then I can move the files from the individual paths.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,618
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Ahhh...see, you need to be more specific!

    Okay...but you still should download that HELP file.

    Oh, and this is called "recursion":

    Code:
    Sub CopyAll( fromF, toFName)
        fs.CopyFile fromF.Path & "\*" , toFName ' copy all files in one folder!
        ' then copy files in any subfolder of this one:
        Set subfs = fromF.SubFolders
        For Each subf In subfs
            CopyAll subf, toFName ' recursion! call ourself for all subfolders
        Next
    End Sub
    
    toFolderName = "c:\some\folder\" ' *MUST* end in backslash!
    path = drive & ":\DCIM\"
    set folder = fs.GetFolder(path)
    
    CopyAll path, toFolderName
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-12-2013)


  •  

    Posting Permissions

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