?
Solved

Script to extract files from folders

Posted on 2013-06-24
5
Medium Priority
?
344 Views
Last Modified: 2013-06-24
I need a turnkey Windows script that will scan a bunch of folders and subfolders and extract windows media audio files *.wma and place them all into a single folder.  I am not sure how best to handle files with duplicate filenames, but I am pretty sure there are none.  Maybe the duplicates could get placed a folder named duplicate.
0
Comment
Question by:murryc
[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
  • 3
  • 2
5 Comments
 
LVL 56

Expert Comment

by:Bill Prew
ID: 39272829
Will there need to be a list of base folders to scan into, or are you wanting to scan a single folder and all it's subfolders?

~bp
0
 

Author Comment

by:murryc
ID: 39272970
I have a single folder called 'Music' but inside of that I have 35 folders and then those 35 folders have various subfolder structures.  Some have a single subfolder, but others might have a folder within their subfolders.  So I have varying levels of subfolders.  I think the script will need to check for unlimited depths of folder levels.
0
 

Author Comment

by:murryc
ID: 39272975
So I can provide the path to the root folder for it to start its scanning of everything within that root folder.
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 39273006
Okay, great, that's easy enough, working that up now...

~bp
0
 
LVL 56

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 39273109
Okay, here's a script for this job, adjust the paths as needed.

' File I/O constants
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Source and xdestination folder names, and extension of files to move
strBaseDir = "C:\EE\EE28166353\Files"
strDestDir = "C:\EE\EE28166353\Merge"
strBaseExt = ".wma"

' Log file for duplicate errors
strLogName = "C:\EE\EE28166353\logfile.txt"

' Create filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open log file
Set objLog = objFSO.OpenTextFile(strLogName, ForWriting, True)

' Call recursive subroutine to move all files in a folder, and all child folders
MoveFiles objFSO.GetFolder(strBaseDir)

' Close log file, release objects
objLog.Close()
Set objLog = Nothing
Set objFSO = Nothing

Function MoveFiles(objFolder)
    ' Process all files in this folder
    For Each objFile in objFolder.Files
        ' Is it the extension we want to move
        If LCase(Right(objFile.Name, Len(strBaseExt))) = LCase(strBaseExt) Then
            ' Build new destination path
            strDestPath = strDestDir & "\" & objFile.Name
            ' Only move it the destination file doesn't exist, otherwise log and leave alone
            If objFSO.FileExists(strDestPath) Then
                objLog.WriteLine "Duplicate file:[" & objFile.Path & "], [" & strDestPath & "]"
            Else
                objFSO.MoveFile objFile.Path, strDestPath
            End If
        End If
    Next

    ' Process all subfolders in this folder
    For Each objSubFolder in objFolder.Subfolders
        MoveFiles objSubFolder
    Next
End Function

Open in new window

~bp
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 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