Solved

Extract  Picutres from directory structure to One folder

Posted on 2004-09-28
4
137 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 101
MsgBox 2 61
VBA to find and replace multiline text from VBA modules 8 90
Help with Classic ASP - Parameterizing Query 16 22
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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