Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Sort And Move Files To Folders
 

Vbscript / Files And Folders / Sort And Move Files To Folders

This script moves files from one place to another based on matching the folder name within the file name.


Set objFSO = CreateObject("Scripting.FileSystemObject")

srcPath = objFSO.getAbsolutePathName(".")
tgtPath = "D:"


  Set objsrc = objFSO.GetFolder(srcPath)
  Set objtgt = objFSO.GetFolder(tgtPath)


i = 0

  For Each tgt In objtgt.subFolders
      For Each src In objsrc.Files

 If inStr(src.Name,tgt.Name) Then
 
  objFSO.copyFile src.Path, tgt.Path & "", True
  i = i + 1
 If objFSO.FileExists(tgt.Path & "" & src.Name) Then
  objFSO.DeleteFile src.Path
 End If
 End If

   Next
   Next 

Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent 0, i & " files moved."





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
          - Auto Copy Files From Cdrom
          - Backup My Documents
          - Cleanup Filenames
          - Create Remote File Share
          - File Properties
          - File Server Report
          - File Type Report Scan
          - Find And Replace Filename Text
          - Find And Replace Text In Files
          - Folder Size Scanner
          - Rename Files Find And Remove Text
          - Rename Files Find And Replace Text
          - Replace Folder Ntfs Security Permissions
          - Simple File Report
          - Sort And Move Files To Folders
          - Windows File Locations
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers