Script to create folders every 500 files

Discuss our other products here. Get help with installation and running, notify us of bugs, request new features and enhancements.

Moderators: DataMystic Support, Moderators

User avatar
DataMystic Support
Site Admin
Posts: 2139
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia

Script to create folders every 500 files

Postby DataMystic Support » Tue Oct 09, 2012 11:07 am

In FileWatcher, specify the command as

Code: Select all


and the parameters as

Code: Select all

Your Path\Group files by 500.vbs

Set FileWatcher to watch c:\incoming

If you edit the .vbs file, you can alter the number of files per folder (default 500), the incoming folder (default c:\incoming), and the base name of new output folders created (default c:\doc).

Code: Select all

'FileWatcher script - move files to a new folder

Option Explicit

const incoming = "c:\incoming"
const maxfiles = 500
'this is the base filename, e.g. c:\doc01, c:\doc02, c:\doc03 ...
const folderbase = "c:\doc"

dim fso
dim files
dim folder

Function getNewFolder()

  'find an unused folderbase name
  dim number
  number = 1
    'does it exist already?
    msgbox folderbase + CStr(number)
   if not fso.folderExists( folderbase + CStr(number) ) then
      msgbox "creating " + folderbase + CStr(number)
     fso.createFolder folderbase + CStr(number)
     getNewFolder = folderbase + CStr(number)
     Exit Function
   end if
   'already exists, try again
    number = number + 1

end Function

'move up to maxfiles files to a new folder
sub moveFiles( files, newFolder )

  dim filename
  msgbox "Moving to " + newFolder
  dim count
  count = 0
  For each filename In files
    msgbox filename
    fso.MoveFile filename, newFolder + "\"
   count = count + 1
   if count >= maxfiles then
      Exit Sub
   end if

end sub

Set fso = CreateObject("Scripting.FileSystemObject")

'Count files in incoming folder
Set folder = fso.GetFolder(incoming)
Set files = folder.Files
if files.count > maxfiles then
  moveFiles files, getNewFolder()
end if

Set fso = Nothing

Simon Carter, - Insulin dose calculator for Type 1 diabetes - 250,000 free software downloads - send huge email attachments

Return to “FileWatcher, DirDate and other Support”

Who is online

Users browsing this forum: No registered users and 1 guest