Solved

Extract  Picutres from directory structure to One folder

Posted on 2004-09-28
4
138 Views
Last Modified: 2010-05-02
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
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 12173608
in DOS, "XCOPY  C:\Source\*.jpg C:\Target\ /S"

The "/S" traverses all sub directories
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 12173625
oops, that preserves the folder structure.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12173669
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12173698
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question