Button to create directory, then copy and paste another directory inside it

Hello all,

I have a button that I use to create a folder structure whenever I start a new project. I have decided I would also like to be able to copy and paste an existing folder into one of those newly created directories. However, I am getting the error "cannot copy a file or folder into itself". This is the code:

@set ProjectName {dlgstring|Enter project name}
CreateFolder READAUTO=no "{$ProjectName}\Audio - Sound Effects"
COPY "D:\Audio\Sound FX & Scores\Benn TK" TO "{$ProjectName}\Audio - Sound Effects"

I'm trying to copy the Benn TK folder as a subfolder for the newly created Audio - Sound Effects folder. What is the correct way to execute this action?

Thank you!

I've attached the error...


I think the destination path of the copy command (since the TO argument is not fully qualified, and there's also no HERE argument) will be relative to the destination folder, which was presumably the Benn TK folder (or something below it) when you were testing.

While you can use the CreateFolder command, you don't need to here. The Copy command can create folders, so you can do this:

@set ProjectName {dlgstring|Enter project name}
Copy "D:\Audio\Sound FX & Scores\Benn TK" TO {sourcepath$} CREATEFOLDER="{$ProjectName}\Audio - Sound Effects"

You could also do everything in one line like this:

Copy "D:\Audio\Sound FX & Scores\Benn TK" TO {sourcepath$} CREATEFOLDER="{dlgstring|Enter project name}\Audio - Sound Effects"

That will copy the Benn TK folder itself into the target. If you want the contents of the Benn TK folder directly below the target, change it to this (adding \* after the first path):

Copy "D:\Audio\Sound FX & Scores\Benn TK\*" TO {sourcepath$} CREATEFOLDER="{dlgstring|Enter project name}\Audio - Sound Effects"

(In theory, you should be able to use HERE instead of the more verbose TO {sourcepath$} in those commands, but it conflicted with CREATEFOLDER=... when I tested it. I think that's a bug, which we'll look into and fix.)

This worked perfectly! Thank you! Also, thanks for the explanation...

I didn't do it on one line because I have other folders I'm creating in the structure that I didn't put in this post and I wasn't sure if it would still work, but thank you!

Also, if I need to add another folder or file to be coped to that same directory Audio - Sound Effects DO I just use the same 'copy' command but without CREATEFOLDER?

Ah OK, that makes sense in that case.

The easiest thing is to keep the CREATEFOLDER argument, and make all the copy lines exactly the same. If the specified folder already exists then it's no problem.

If you remove the CREATEFOLDER argument, you'd need to instead add a TO argument specifying the same folder, otherwise the other copies would end up in the wrong place.

I looked into that and found the issue. Using HERE with these commands should work in the next beta, but using TO {sourcepath$} instead is fine as well, and I'm just mentioning it for completeness. One is (or at least should be!) just a shorthand for the other really.

EDIT: That change was in 12.25.1 beta but we've decided to roll it back as it fixed one rare situation but broke another. We have a larger change which we're testing internally but want to test for a while before we release it, since it refactors things somewhat and thus has more potential to cause problems.

Oh ok, that makes perfect sense.

Thanks as always!!

1 Like

Also, a tip you might find useful. The CREATEFOLDER command can create multiple levels in one command.

For example, let's say I have a folder named "Projects" (on the D drive) and it's completely empty (no files or folders under it). I could use a command like:

CreateFolder "D:\Projects\2021 Family Trip\Photos\Archive"

It will create a "2021 Family Trip" folder in Projects, with a Photos sub-folder. The Photos folder will have its own sub-folder named Archive.

You can do even more. For work, I have to update two monthly reports (as opposed to six months ago where I had to update 7 every week and one report once a month...we've reduced it a lot because we're using fancy-shmancy Power BI reports instead. Yay!). The button command below creates the folder structure I need. I click it on the 1st of the month (or the first workday after the first).

CreateFolder "{date|yyyy-MM-01} (007 Report)\No Records Found" "{date|yyyy-MM-01} (Revenue)\No Records Found"

You'll notice this has two arguments. That's because CreateFolder lets you specify multiple paths that you want to create in one single command. In total, this single command is creating four folders. When I use this on Monday, November 1st, it will create:


It's so handy to have these little repetitive things tucked away in a button. By the way, you'll notice I used date codes in the folder name so it will create it for the correct year and month. But, since these reports work on data that's automatically generated and delivered on the 1st of each month, I don't use a dynamic "day of month" token. Instead, I hard-code 01 as the day of the month.

If you already knew this stuff, my apologies for presenting you with redundant information. Perhaps it will be useful to someone else in the future.

1 Like

I did not know any of it, very useful tips...I love this community!

Thank you!

Updating my comment above about using HERE, if you switched to using HERE with 12.25.1 beta, please switch back to TO {sourcepath$} as we're going to roll back that change in 12.25.2 beta and later versions.

We're testing a better fix that works in all situations we've tested so far, but it's a much larger change and we want to test it internally for some time before we push it to users, given there's a simple workaround for the problem and no rush.

(Regardless of which version you're using, the HERE command works in general. It's just an issue when combining it with CREATEFOLDER in certain situations, where TO {sourcepath$} should work instead.)