CreateNumberedFolders - User Command

Please read this entire post before proceeding!

This user command has been stress tested in Windows XP. But it should work right away in Windows Vista, and possibly Windows 2000 (it may require rework for Windows 2000).

If you have one of these operating systems, try out the button in an empty test folder, before using it in one of your production folders. It would be great if someone with Windows 2000 would post back with results.

NOTE: This User Command is not supported in Windows/95/98/ME/NT.


CreateNumberedFolders - User Command

This user command allows you to create several numbered folders with the same base name. CreateNumberedFolders is actually a NT command script that accepts some Opus command options, provides logic branching, and asks Opus to perform some tasks. The command template is:

BASENAME/K/A, FROM/K, TO/K/A, BY/K, WAITINTERVAL/K[ul][li]BASENAME/K/A - The base name of the folder ("New Folder - " in the example command below). Include any desired divider character between the base name and the number as part of the base name itself.
[li]FROM/K - The starting number for the first folder. Add leading zeroes to this value, if you wish to pad shorter numbers to a certain number of characters. Thus, FROM=0025 would number the first folder 0025 and ensure that all numbers would be padded to four digits using leading zeroes when necessary. If this option is omitted, the command assumes a default of 1 and no padding with leading zeroes.
[li]TO/K/A - The highest number folder created. The command has been stress tested to 10,000 folders and it should handle more if required.
[li]BY/K - Use this option to specify the increment used between successive folder numbers, starting with the number specified in the TO option. Thus BY=10 would number folders by 10 instead of the default of numbering them by 1.
[li]WAITINTERVAL/K - There are a couple of places where the script must wait for Opus to finish its operation or update its file list, before the script can progress safely to its next command. Otherwise, the script and Opus will be in a race condition, where the script expects all folders to be created or selected but the file listing hasn't been updated yet.

I have stress tested this command for as few as 1 and as many as 10,000 folders using the default wait interval of 3 seconds. However, I cannot anticipate what else may be running on your system. Should you experience errors in your folder names, try increasing WAITINTERVAL. You could also try a smaller value, but this is not recommended.

Character Limitations in folder names:
For performance reasons CreateNumberedFolders uses the Command Prompt command MakeDir to create its folders, rather than the Opus CREATEFOLDER command (stress testing has proven MakeDir is much faster). As a result, folder names are limited to those characters supported by the MakeDir command and NT Command scripts. (In general, Windows XP is more liberal in what characters may be used.)

Directory Opus also has an issue (that I discovered when scripting this command) when selecting folders or files by pattern, if the name contains the "~" character. If you use a base name with this character, the folders will be created, but they will not have the names you expect. This is also due in part to a separate Opus issue that I needed to script around.

IMPORTANT: Using this command from within Windows Namespace folders, like My Computer, will result in errors and is strongly not advised![/li][/ul]

USAGE EXAMPLES: (All Usage Examples are included in the .zip download file.)

  • Create 10 folders numbered from 10 to 100 by 10 and padding all numbers to three digits.

    CreateNumberedFolders BASENAME="New Folder - " FROM=010 TO=100 BY=10 WAITINTERVAL=2

    The output of this command is:

    New Folder - 010
    New Folder - 020
    New Folder - 030
    New Folder - 040
    New Folder - 050
    New Folder - 060
    New Folder - 070
    New Folder - 080
    New Folder - 090
    New Folder - 100
  • Create multiple numbered folders with same base name. Default the base name to "New Folder - ", the numbering from 10 to 100 by 10, and number padding to three digits. Prompt the user to override each value before executing.

    Runmode Hide
    dopusrt /CMD CreateNumberedFolders BASENAME="{dlgstring|Enter base name for all folders:|New Folder - |}" FROM={dlgstring|Enter starting number (pad with leading zeroes if padding is desired):|010} TO={dlgstring|Enter highest number:|100} BY={dlgstring|Enter amount to increment folder numbers by:|10}

    The default output of this command is the same as that of example 1. above; however, the user may override the option values on-the-fly.


[ul][li] Version 1.2 - Modified the User Command script to allow toolbar buttons to utilize dopusrt /CMD syntax. This syntax allows the user to create a button that will prompt for all required option values. Such a button is more practical for creating folders on-the-fly. A sample button that makes use of this syntax is included in the .zip download file.
[li] Version 1.0 - Original download file (unversioned).[/li][/ul]

HOW TO CORRECTLY GET THE COMMAND TO YOUR DIRECTORY OPUS CONFIGURATION:[ol][li] Download the attached .zip file and extract it to a folder.[/li]
[li] List the folder in an Opus lister.[/li]
[li] Right-click any Opus toolbar and select Customize.[/li]
[li] Click on the Customize > Commands Tab.[/li]
[li] Click on the User Category.[/li]
[li] Drag CreateNumberedFolders-UserCommand.dcf to the User Commands list.[/li]
[li] From the User Commands list, drag the command to any toolbar and edit its options to suit your needs.[/li][/ol]

Remember CreateNumberedFolders is a User Command not a Toolbar Button!

The CreateNumberedFolders command code is structured differently from most other toolbar buttons. User Commands differ greatly from Toolbar buttons. For instance, once a User Command is created, it can be used from inside other Toolbar Buttons. If its template is configured correctly, any qualified options for a user command will be displayed in its Arguments List in the Advanced Command Editor.

When Directory Opus User Commands are exported to a Directory Opus Command (*.dcf) files, they appear very much like exported Toolbar Buttons. User Commands, that do not utilize a Command Template, can be exported to a *.dcf file and subsequently dragged directly to a Directory Opus toolbar to create a Toolbar Button without actually creating the related User Command.

IMPORTANT: User Commands that do utilize a Command Template (like CreateNumberedFolders) cannot be directly dragged to a toolbar--doing so will create a Toolbar Button with no Command Template, breaking the intended functionality of the user command.

I hope you find this useful :smiley: and educational :bulb: (6.47 KB)

This command has been updated. Read the Release Notes in the first post for changes and download the new version.

I know this post is really old... but is it possible to get it updated for Win7? or is there another way to do the same thing?


No idea who originally wrote this, I know I didn't. Credit to whoever did.

Create a button that runs a "Standard Function (Opus or External)" with this code:

[code]Rename FILEINFO FROM="." TO="{DlgStringS|Folder name and number range to create:|Folder Name,1,20}"
@script vbscript
Option Explicit

' Number of digits to pad the number to. For example, if PadTo
' is 3 then the script will generate 001, 002, 003, 004, etc..
Dim intPadTo
intPadTo = 3

' For information on the technique used in this button see:
' "Abusing" Rename Scripts to do other things with file info
' [OBSOLETE] "Abusing" Rename Scripts to do other things with file info

Dim Shell
Set Shell = CreateObject("WScript.Shell")

Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")

Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)

Dim strTemp
Dim strFolderName
Dim intLast
Dim intCurrent
Dim strCurrent
Dim strCreatePath
Dim intComPos

if intPadTo < 1 then
	intPadTo = 1
end if

strFolderName = ""
intCurrent = 0
intLast = 0

intComPos = InStrRev(strNewName,",")
if intComPos > 0 then

	strTemp = Trim(Right(strNewName,Len(strNewName)-intComPos))

	if IsNumeric(strTemp) then

		intLast = CInt(strTemp)

		strTemp = Trim(Left(strNewName, intComPos-1))

		intComPos = InStrRev(strTemp,",")

		if intComPos > 0 then
			strFolderName = Trim(Left(strTemp, intComPos-1))
			strTemp = Trim(Right(strTemp,Len(strTemp)-intComPos))

			if IsNumeric(strTemp) then
				intCurrent = CInt(strTemp)
				strFolderName = "" ' Prevent anything from happening
			end if
		end if
	end if
end if

' Set strNewName to an empty string so that Opus does not rename the file.
strNewName = ""

if strFolderName <> "" then

	while intCurrent <= intLast
		strCurrent = CStr(intCurrent)
		If Len(strCurrent) < intPadTo Then
			strCurrent = String(intPadTo - Len(strCurrent), "0") & strCurrent
		End If

		strCreatePath = strFilePath & "\" & strFileName & "\" & strFolderName & " " & strCurrent

		if fs.FolderExists(strCreatePath) or fs.FileExists(strCreatePath) then
			DOpus.OutputString "Skipping " & strCreatePath
			DOpus.OutputString "Creating " & strCreatePath
		end if

		intCurrent = intCurrent + 1
end if

End Function[/code]

The default settings in the above code will create:

Folder Name 001 Folder Name 002 . . . Folder Name 019 Folder Name 020

When clicked, the script will ask you what the folder name and range is to be. Entered in as so:

Folder Name,Starting Number,Ending Number

The code above is set to use 3 digits for the numbering, but you can change that by adjusting this line:

intPadTo = 3

Thanks very much. I use this all the time when i shoot panoramic photos and i want to separate the files into individual folders for archival.