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...

image

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.

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:

image

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.

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

Thank you!