GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Help with the name of the first selected file

Hi guys, I've created a new button that creates a new folder, and if you have any files/folders selected moves them into that folder, in both cases popping up a dialog asking for the name of the new folder. The bit I'm having trouble with is I want the default name of the folder to be the name of the first selected file. The original button looks like this, and works:

@nofilenamequoting @set dir = {dlgstring|Enter new subfolder name| "new folder"} createfolder "{$dir}" Rename TO="{$dir}\*"

But can you tell me why this doesn't work?

@nofilenamequoting @set startname = {file} @set dir = {dlgstring|Enter new subfolder name| {$startname}} createfolder "{$dir}" Rename TO="{$dir}\*"

{file} should return the name of the first selected file, if there is one, but what actually appears in the new-folder-name dialog box is the literal string "{file}". Any ideas on why this is so, and what needs changing to make it work...?

I assume you want to be able to run the command with nothing selected to create a folder, which is why you're using Rename to move the files. If so then I think this is what you want:

@set dir = {dlgstringS|Enter new subfolder name|{file|noext}} CreateFolder NAME="{$dir}" READAUTO=no Rename TO="{$dir}\*"

If you don't want the command to do anything if no files are selected (or if you don't care either way) then you can simplify it by using Copy instead of CreateFolder and Rename:

@set dir = {dlgstringS|Enter new subfolder name|{file|noext}} Copy MOVE HERE CREATEFOLDER="{$dir}"

Note: Some of the changes I made to your original buttons are not required to make it work but seem like good ideas all the same. I used dlgstringS instead of dlgstring, so the default name is initially selected and you can type over it if you want something else. I also made the CreateFolder NAME argument explicit (so you don't run into problems creating folders whose names are other arguments, e.g. a folder called ZIP) and added READAUTO=no to ensure the new folder isn't read in.

Edit: Oh yeah, I also made it use {file|noext} instead of {file} since you probably don't want the file extension in the folder name and creating a folder with the same name as a file (including extension) isn't allowed on Windows.

[quote="leo"]
Note: Some of the changes I made to your original buttons are not required to make it work but seem like good ideas all the same. I used dlgstringS instead of dlgstring, so the default name is initially selected and you can type over it if you want something else. I also made the CreateFolder NAME argument explicit (so you don't run into problems creating folders whose names are other arguments, e.g. a folder called ZIP) and added READAUTO=no to ensure the new folder isn't read in.

Edit: Oh yeah, I also made it use {file|noext} instead of {file} since you probably don't want the file extension in the folder name and creating a folder with the same name as a file (including extension) isn't allowed on Windows.[/quote]

Wow leo you absolutely read my mind! I've approved all the changes, but unfortunately it still doesn't work for me, I'm still presented with the same problem - I'm not actually getting a filename when using {file}. I've copy-pasted your first button straight into my setup, and this is what I get in the dialog - (see screenshot). Do you think this is a bug?

Set the button type to MS-DOS. I'm not sure why but it fixes the problem. (I noticed this the other day with a similar button.)

As it happened I was playing around with an old button that was already set to the MS-DOS type so I didn't realise what I posted depended on it.

BTW I think there's a typo in your toolbar: Oraganise.

Ha! Well spotted on the typo, I can't tell you how long ago I made that menu and never noticed. You're right, changing to DOS function did fix it, how odd. Still - all's well that ends well.

This is a bug of DOpus. Read Creating folders from filename and Assign selected file/foldername as a value to a variable? topics for more details.