Copying a folder structure via User Command?

Non-programmer here, so forgive me if my code looks absolutely bone-headed :slight_smile:.

I typically have to create a common set of sub-directories under a folder every month. To accomplish, I usually use an XCOPY command like so:

XCOPY /T R:\SPOOL\MAY R:\SPOOL\JUNE\

I usually run this command by navigating to the folder in Dopus and then choosing "DOS Prompt Here" from the right-click menu.

I figured this would be more easily accomplished by writing a Dopus User command and so did the following:

  1. Choose Settings>Customize>Commands>User>New

  2. Searching around in the Dopus Help and in the forum, I couldn't figure out a Dopus RAW command to accomplish, so I decided to stick to XCOPY.

  3. Chose Function Type as MS-DOS batch function

  4. created the following code

@set folder = {dlgstring} CreateFolder R:\SPOOL\{$folder} XCOPY {sourcepath} /T R:\SPOOL\{$folder}\ pause

To keep things simple I assumed I would select this command from inside a lister where the folder structure I wanted to replicate was selected.

The pause command was added for debugging.

  1. Unfortuantely, the code didn't work :frowning: . I get an error message "Invalid path"

I'm guessing the @set combined with dlgstring doesn't work and hence the $folder variable stays empty (or something like that).

Please help this newbie out!

PS: I have managed to sell atleast 4 colleagues at work into switching to Dopus.. I love this app :smiley:

I haven't got time atm to look at this - it's late and I'm off to sleep.

but...

Is it just a matter of quotation marks?

XCOPY "{sourcepath}" /T "R:\SPOOL{$folder}"

[quote="tanis"]I haven't got time atm to look at this - it's late and I'm off to sleep.

but...

Is it just a matter of quotation marks?

XCOPY "{sourcepath}" /T "R:\SPOOL{$folder}"[/quote]

Invalid path error like before unfortunately :frowning:

This seems to work for me:

@set folder = {dlgstring} xcopy /T /E /I "{sourcepath$|noterm}" "D:\TEST\{$folder}\"

You'll need to change the paths to suit. The CreateFolder you were using is redundant as XCOPY will create the folder as required. The "|noterm" addition to the {sourcepath$} argument simply tell Opus not to include the trailing backslash for the path.

The arguments used for xcopy are:

/T - Creates directory structure but does not copy files
/E - Modifies the /T argument to include empty folders
/I - Forces XCOPY to assume that the destination provided is a folder.

You can add "@runmode hide" as the first line to prevent the command prompt window flashing open.

Note: Xcopy doesn't cope if the source folder is the same as the destination so it falls over with a cyclic copy error if that's the case.

Actually, everything you did was fine... the problem is that XCOPY doesn't like the trailing backslash that Opus passes at the end of the {sourcepath} control code. Modify your button to the following and you should be good:

@set folder = {dlgstring}
CreateFolder D:\MY\TEMP{$folder}
XCOPY {sourcepath|noterm} /T D:\MY\TEMP{$folder}\
pause

Note1: when "debugging" this sort of issue (particularly with 'batch mode' functions) it's often helpful to prepend an echo statement at the beginning of some of the commands... this way, you can see in the paused console window what all the variables and control codes are being expanded to, and from there start working with the "real" values being tossed aroung outside of Opus to see if external application calls fail when run manually, and figure out from there what's going wrong.

Note2: you can do the same sort of thing using the Opus Copy function and a 'folders only' copy filter, like so:

  • unzip and copy the attached filter file (folders.ofi) into the /dopusdata\Filters folder
  • edit a button or hotkey or however you're running the command (no need to make 'this' modified command an MS-DOS batch function type or 'user' command) to run simply: Copy AS FILTER=folders
    folders filter.zip (373 Bytes)

Woopsy... had my reply window open too long... HOWDY STEVE!

Hi. :slight_smile:

tanis and steje - thank you for the help!

@tanis - It worked! It worked!! :smiley: - the |noterm was all that was required. Of course, I immediately became a bit greedy and tried to make it such that I could define the sourcepath as a variable as well.

I tried this

@set folder = {dlgstring} @set source = {dlgfolder} xcopy /T /E /I "{$source}" "R:\{$folder}\"

But using dlgfolder adds a trailing slash to the path and I can't use noterm to strip it out :frowning: . I guess some kind of regex would work, but I haven't gotten that fancy yet :wink: . For now, I've hard-coded the sourcepath to an existing folder instead - that way, if ever have a brain-f*rt and click on the User command while in a different lister, I won't be screwed.

@steje Thank you very much for the tip on echo - I was struggling to figure out how to display the variable value. Which tells you how "good" I am at programming anything :stuck_out_tongue:

As well as the echo command you can also use my doptest program which gives some additional options when testing command lines.

If the destination folder is always the current month name then you might be able to make the button even more convenient using {date|MMMM} which will turn into July right now.

It is a month-name, but usually of the previous month. Is there any way to obtain the previous month code using the date function?

No, I don't think there is a way to add/subtract time from the current date/time.

Well, regardless of whether you want to stick with Xcopy or go with the native Opus Copy function with a folder filter... either way will 'copy' your data.

Since you'd only ever be copying "one" folder, maybe you can write a button that will copy a select folder to a 'staic' folder name, then in the same button run a vbscript that we could write which would take the current date/month, and then do the "math" needed to figure out the "previous" months name, and let the script actually rename your copied 'static' folder name (say foo) to the desired monthly name...?

[quote="steje"]Well, regardless of whether you want to stick with Xcopy or go with the native Opus Copy function with a folder filter... either way will 'copy' your data.

Since you'd only ever be copying "one" folder, maybe you can write a button that will copy a select folder to a 'staic' folder name, then in the same button run a vbscript that we could write which would take the current date/month, and then do the "math" needed to figure out the "previous" months name, and let the script actually rename your copied 'static' folder name (say foo) to the desired monthly name...?[/quote]

Yes that sounds like it would be the only way to do it, if we want to do it completely via scripting. However, I have never really done any programming in VBScript, so I'm a bit of a loss where to begin.

I will see if I can find the time to poke around this weekend though!

Thanks for the advice!