Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

Extract Picutres from directory structure to One folder

vb6 sp5
win 2000 sp4

I need a routine that will copy ALL pictures .jpg  files from a folder that has Many subfolders and place the jpg. in ONE folder

Ther .jpg files start in a folder called  c:\pics\

I need to place ALL the jpg  files in a folder called  c:\Newjpg\


Thanks
fordraiders
0
Fordraiders
Asked:
Fordraiders
  • 2
1 Solution
 
JohnBPriceCommented:
in DOS, "XCOPY  C:\Source\*.jpg C:\Target\ /S"

The "/S" traverses all sub directories
0
 
JohnBPriceCommented:
oops, that preserves the folder structure.
0
 
David LeeCommented:
Here's a VBScript that'll do this.  If you want straight VB, then it'd be very easy to convert this.

Usage: CopyJPGs.vbs SourcePath
Example:  CopyJPGs.vbs C:\pics

---- Script CopyJPGs.Vbs
Dim objFSO, _
    intFolders, _
    intFiles, _
    strStartingPath

    strStartingPath = Wscript.Arguments.Item(0)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ProcessFolder strStartingPath
    Set objFSO = Nothing
    Wscript.Echo "Folders Processed: " & intFolders & " Files Changed: " & intFiles
    Wscript.Quit

Sub ProcessFolder(strFolderPath)
    Dim objFolder, _
        objSubFolders
    'Create the starting folder object
    Set objFolder = objFSO.GetFolder(strFolderPath)
    'Call the ProcessFiles subroutine and pass it the folder object
    ProcessFiles objFolder
    intFolders = intFolders + 1
    'Create the sub-folders object
    Set objSubFolders = objFolder.SubFolders
    'Loop through the sub-folders in the folder object
    For Each objFolder In objSubFolders
        'Call the ProcessFiles subroutine and pass it the sub-folder object
        ProcessFolder objFolder.Path
    Next
    'Dispose of the created objects
    Set objSubFolders = Nothing
    Set objFolder = Nothing
End Sub

Sub ProcessFiles(objFolder)
    Dim objFile, _
        strFileType
    'Loop through the files in the folder object
    For Each objFile In objFolder.Files
        strFileType = LCase(objFSO.GetExtensionName(objFile.Name))
        If strFileType = "jpg" Then
            objFSO.CopyFile objFile.Path, "C:\NewJpg", True
            intFiles = intFiles + 1
        End If
    Next
    'Dispose of the object created in this subroutine
    Set objFile = Nothing
End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is another way to do it:

Option Explicit

Private Sub Command1_Click()
    moveFiles "c:\pics\", "*.jpg", "c:\Newjpg\"
    MsgBox "Done"
End Sub

Private Sub moveFiles(ByVal basePath As String, ByVal filter As String, ByVal targetPath As String)
    Dim curFile As String
    Dim subdir As Variant
    Dim subDirs As Collection
       
    ' copy the files
    curFile = Dir(basePath)
    Do
        If curFile <> "" Then
            If curFile Like filter Then
                FileCopy basePath & curFile, targetPath & curFile
            End If
        End If
        DoEvents
        curFile = Dir()
    Loop While curFile <> ""
   
    ' build subDirs collection
    Set subDirs = New Collection
    curFile = Dir(basePath, vbDirectory)
    Do
        If curFile <> "" Then
            If (GetAttr(basePath & curFile) And vbDirectory) = vbDirectory Then
                If curFile <> "." And curFile <> ".." Then
                    subDirs.Add basePath & curFile & "\"
                End If
            End If
        End If
        DoEvents
        curFile = Dir()
    Loop While curFile <> ""
   
    ' recurse into each subdir
    For Each subdir In subDirs
        moveFiles subdir, filter, targetPath
    Next
End Sub
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now