Copy sequential folder with increment

Thanks Leo :slight_smile:

I did the button installation correctly and select my last folder with the same names as in your video and i get an error telling this:

Windows cannot find 'option' . Make sure you type the name correctly, and then try again.

I have a question a bout the video.
In your example I can read 3 folders:

1512_72up_051214
1513_72up_051214
1514_72up_051214

When you execute the script, the name of the new folders are different from the template folder.
I don't want the script choose the new name for me.
I don't want the script pick the current date, this is not what i expect.

Each time i need to duplicate my template folder i will rename it, then rename the files inside before duplicating.
The duplicated folders will only have the increment of the numbers before _72up_051214

I hope to get that script work, it is very interesting to be able to input the number of folders! :thumbsup:

I think this is not working because the date format.

I use that date format:

English (Canada)

Short date: dd/MM/yyyy
Long date: d-MMM-yy
Short time: h:mm:tt
Long time: h:mm:ss tt

It could do that if the button type wasn't set to Script Function (e.g. if you pasted the script itself into a button, instead of using the XML to create a new button).

Or if you're using Opus 10. (I assumed Opus 11, but if that's wrong then Opus 10 doesn't support script buttons so my solution won't work there.)

Opus 10 :wink:

Hum much is it to upgrade to Opus 11?

See gpsoft.com.au/DScripts/upgrade.asp

Hello Leo,

I get my opus upgraded to 11. :thumbsup:

Now your xml script is working but it doesn't do exactly what expected..

The script need to do this:

-The last selected folder will be duplicated a X number of time.
-A requester appear and asking for the number of duplicate and the new name if the user want to change it.
( actually I rename my template folder manually. The date in the name is never the actual day)
-The folder number will increment (actually your script do the good thing)
-The .aep and .xls files will be renamed with the same folder name accordingly.

See my folder template listing attached

Thanks and your help is very appreciated. :smiley:


This is the result expectred (see attached)

Actually my account doesn't give me permission to send you a personal message.
Please tell me where i can have a private conversation with you. (this is about a special need and i cannot talk about it in public)

Thanks :slight_smile:


Please try this new version:

<?xml version="1.0"?> <button backcol="none" display="both" label_pos="right" textcol="none"> <label>Duplicate Template Folder</label> <icon1>#default:newcollection</icon1> <function type="script"> <instruction>option explicit</instruction> <instruction /> <instruction>Function ZeroPad(str, slen)</instruction> <instruction> str = CStr(Str) &apos; Force To String.</instruction> <instruction> If (Len(str) &lt; slen) Then</instruction> <instruction> str = String(slen - Len(str), &quot;0&quot;) &amp; str</instruction> <instruction> End If</instruction> <instruction> ZeroPad = str</instruction> <instruction>End Function</instruction> <instruction /> <instruction>Function IsLongInteger(str)</instruction> <instruction> IsLongInteger = False</instruction> <instruction> If (IsNumeric(str)) Then</instruction> <instruction> &apos; Not really needed, but make sure the number doesn&apos;t have a decimal point.</instruction> <instruction> If (CStr(CLng(str)) = CStr(str)) Then</instruction> <instruction> IsLongInteger = True</instruction> <instruction> End If</instruction> <instruction> End If</instruction> <instruction>End Function</instruction> <instruction /> <instruction>Function OnClick(ClickData)</instruction> <instruction> Dim dlgTitle, tab, dlg, cmd, numFolders, regexp, matches</instruction> <instruction> Dim fullName, namePrefix, nameSuffix, prefixLen, nowDate, i</instruction> <instruction> Dim fsu, folderEnum, currentPrefix, currentPath, currentItem</instruction> <instruction> Dim origName, origNameUpper, origNameUpperDot, origNameUpperLen, testUpper</instruction> <instruction> dlgTitle = &quot;Duplicate template folder&quot;</instruction> <instruction> nowDate = Date()</instruction> <instruction> Set tab = Clickdata.func.sourcetab</instruction> <instruction> Set dlg = ClickData.func.Dlg</instruction> <instruction> Set cmd = ClickData.func.command</instruction> <instruction> Set regexp = New RegExp</instruction> <instruction> Set fsu = DOpus.FSUtil</instruction> <instruction /> <instruction> cmd.deselect = False</instruction> <instruction /> <instruction> &apos; Check exactly one folder is selected.</instruction> <instruction /> <instruction> If (tab.selected_dirs.count &lt;&gt; 1 Or tab.selected_files.count &lt;&gt; 0) Then</instruction> <instruction> dlg.Request &quot;Select one folder to duplicate.&quot;, &quot;OK&quot;, dlgTitle</instruction> <instruction> Exit Function</instruction> <instruction> End If</instruction> <instruction /> <instruction> origName = tab.selected_dirs(0).name</instruction> <instruction /> <instruction> &apos; Split the folder name up to take the counter from the start.</instruction> <instruction /> <instruction> regexp.IgnoreCase = True</instruction> <instruction> regexp.Global = True</instruction> <instruction> regexp.Pattern = &quot;^(\d+)_(.+)$&quot;</instruction> <instruction> Set matches = regexp.Execute(origName)</instruction> <instruction> If (matches.count &lt; 1) Then</instruction> <instruction> dlg.Request &quot;Selected folder&apos;s name does not fit the expected pattern.&quot;, &quot;OK&quot;, dlgTitle</instruction> <instruction> Exit Function</instruction> <instruction> End If</instruction> <instruction /> <instruction> namePrefix = matches(0).SubMatches(0)</instruction> <instruction> nameSuffix = matches(0).SubMatches(1)</instruction> <instruction /> <instruction> prefixLen = Len(namePrefix)</instruction> <instruction> namePrefix = CLng(namePrefix)</instruction> <instruction /> <instruction> &apos; Ask how many copies to make.</instruction> <instruction /> <instruction> dlg.Select = True</instruction> <instruction> dlg.default = &quot;1&quot; &apos; Default number of folders to create</instruction> <instruction> dlg.max = 4 &apos; Max string length. More than 9999 folders would probably be a mistake.</instruction> <instruction> dlg.buttons = &quot;OK|Cancel&quot;</instruction> <instruction> dlg.message = &quot;Number of folders to create:&quot;</instruction> <instruction> dlg.title = dlgTitle</instruction> <instruction> If (dlg.Show() &lt;&gt; 1) Then</instruction> <instruction> Exit Function &apos; Cancelled</instruction> <instruction> End If</instruction> <instruction> numFolders = dlg.Input</instruction> <instruction /> <instruction> If (Not IsLongInteger(numFolders)) Then</instruction> <instruction> dlg.Request &quot;Invalid number of folders entered.&quot;, &quot;OK&quot;, dlgTitle</instruction> <instruction> Exit Function</instruction> <instruction> End If</instruction> <instruction /> <instruction> numFolders = CLng(numFolders)</instruction> <instruction /> <instruction> &apos; Ask for the new name.</instruction> <instruction /> <instruction> dlg.Select = False</instruction> <instruction> dlg.default = nameSuffix</instruction> <instruction> dlg.max = 255</instruction> <instruction> dlg.buttons = &quot;OK|Cancel&quot;</instruction> <instruction> dlg.message = &quot;Name for the new folders (number will be prefixed automatically):&quot;</instruction> <instruction> dlg.title = dlgTitle</instruction> <instruction> If (dlg.Show() &lt;&gt; 1) Then</instruction> <instruction> Exit Function &apos; Cancelled</instruction> <instruction> End If</instruction> <instruction> nameSuffix = &quot;_&quot; &amp; Trim(dlg.Input)</instruction> <instruction /> <instruction> If nameSuffix = &quot;_&quot; Then</instruction> <instruction> dlg.Request &quot;No folder name given.&quot;, &quot;OK&quot;, dlgTitle</instruction> <instruction> Exit Function</instruction> <instruction> End If</instruction> <instruction /> <instruction> &apos; Warn if any prefix numbers in the range we are about to create are already in use.</instruction> <instruction> </instruction> <instruction> Set folderEnum = fsu.ReadDir(Clickdata.func.sourcetab.path, False)</instruction> <instruction> Do While Not folderEnum.Complete</instruction> <instruction> Set matches = regexp.Execute(folderEnum.Next.name)</instruction> <instruction> If (matches.count &gt; 0) Then</instruction> <instruction> currentPrefix = CLng(matches(0).SubMatches(0))</instruction> <instruction> If (currentPrefix &gt;= (namePrefix + 1)) Then</instruction> <instruction> If (dlg.Request(&quot;Folders already exist with prefix &quot; &amp; (namePrefix + 1) &amp; &quot; or above.&quot; &amp; vbCrLf &amp; &quot;Are you sure you wish to continue?&quot;, &quot;Continue|Cancel&quot;, dlgTitle) &lt;&gt; 1) Then</instruction> <instruction> Exit Function</instruction> <instruction> End If</instruction> <instruction> Exit Do</instruction> <instruction> End If</instruction> <instruction> End If</instruction> <instruction> Loop</instruction> <instruction /> <instruction> &apos; Create the duplicate folders</instruction> <instruction /> <instruction> currentPrefix = namePrefix</instruction> <instruction /> <instruction> origNameUpper = UCase(origName)</instruction> <instruction> origNameUpperDot = origNameUpper &amp; &quot;.&quot;</instruction> <instruction> origNameUpperLen = Len(origNameUpper)</instruction> <instruction /> <instruction> For i = 1 To numFolders</instruction> <instruction> currentPrefix = currentPrefix + 1</instruction> <instruction> fullName = ZeroPad(currentPrefix, prefixLen) &amp; nameSuffix</instruction> <instruction> cmd.RunCommand &quot;Copy DUPLICATE HERE AS=&quot;&quot;&quot; &amp; fullName &amp; &quot;&quot;&quot;&quot;</instruction> <instruction /> <instruction> &apos; Rename files below the folder to use the new name, if they were using the old name.</instruction> <instruction> currentPath = Clickdata.func.sourcetab.path &amp; &quot;\&quot; &amp; fullName</instruction> <instruction> Set folderEnum = fsu.ReadDir(currentPath, False)</instruction> <instruction> Do While Not folderEnum.Complete</instruction> <instruction> Set currentItem = folderEnum.Next</instruction> <instruction> testUpper = UCase(currentItem.name)</instruction> <instruction> If (testUpper = origNameUpper Or Left(testUpper,origNameUpperLen+1) = origNameUpperDot) Then</instruction> <instruction> cmd.RunCommand &quot;Rename FROM=&quot;&quot;&quot; &amp; currentItem.realPath &amp; &quot;&quot;&quot; TO=&quot;&quot;&quot; &amp; fullName &amp; Mid(currentItem.name,origNameUpperLen+1) &amp; &quot;&quot;&quot;&quot;</instruction> <instruction> End If</instruction> <instruction> Loop</instruction> <instruction> Next</instruction> <instruction /> <instruction> &apos; Select what was created</instruction> <instruction /> <instruction> cmd.RunCommand &quot;Select NONE&quot;</instruction> <instruction /> <instruction> currentPrefix = namePrefix</instruction> <instruction /> <instruction> For i = 1 To numFolders</instruction> <instruction> currentPrefix = currentPrefix + 1</instruction> <instruction> fullName = ZeroPad(currentPrefix, prefixLen) &amp; nameSuffix</instruction> <instruction> cmd.RunCommand &quot;Select MAKEVISIBLE EXACT PATTERN=&quot;&quot;&quot; &amp; fullName &amp; &quot;&quot;&quot;&quot;</instruction> <instruction> Next</instruction> <instruction /> <instruction>End Function</instruction> </function> </button>

It will ask how many folders to create, as before, and will then ask for the name of the new folders.

The name you see/type doesn't include the counter. So if you're duplicating "1514_72up_051214" it will show you "72up_051214" which you can then edit, and it will add the number back on the front before making the folders.

After it makes the duplicate folders, it will look in them for any files which had the same names as the old folder (ignoring the file extension part), and rename them to match the new folder name.

I didn't restrict the renaming to just .aep and .xls files, but could do that if needed. It will work with anything that is either exactly the same as the old directory name (without an extension), or is the old directory name plus a dot, plus anything else after the dot.

Ohh Woow!

Thanks Leo :slight_smile:

I try the new script asap!

I need another very important feature to refine and complete my workflow..

I need to do an advanced selection with more than the 260 character limit...
Example: Name Match (223081|170449|194322|223359)

It is possible to use the advanced selection with an exel sheet?
(xls csv or xlsm)

Maybe Opus is able to read each cell from the Filename column (highlighted in blue) and the select each *###########.jpg files in the lister.
This is to extract the jpg relative to the exel sheet and then move that selection to the famous incremented folders :slight_smile:

If i need to delete every other cells and only keep one column with the Filename numbers it is no problem in the workflow.

see attached.


[quote="Pag"]Ohh Woow!

Thanks Leo :slight_smile:

I try the new script asap![/quote]

I done the new script testing and it work perfectly!!!
Thank you so much!!!! :slight_smile:

Opus is the tool of choice to solve all these repetitive task!

[quote="Pag"]I need another very important feature to refine and complete my workflow..

I need to do an advanced selection with more than the 260 character limit...
Example: Name Match (223081|170449|194322|223359)[/quote]

This should go into a new thread. (Guidance here.)

A script which reads the file and selects the items would probably make most sense, but to write the script will require some sample input files.

OK sorry

Thanks Leo for your script!

:slight_smile: