A problem with a button changing directory

Hi,

Below is a button I would like to run it from the flat view (Standard function), selecting multiple files.
It:

  • creates a directory named after a selected file in its directory
  • CDs to the directory of the file
  • runs a command creating some files
  • moves created files to the created directory

The problem is, that when multiple files are selected, it works only for the last file (apparently cd doesn't work as expected in such a case). Please mind, the program must work on files in current directory.

Any ideas?

@codepage:852
CreateFolder {filepath$|..}{file$|noext}
cd {filepath$|..}
C:\Programy\program.exe -c {file$}
Rename FROM {filepath$|..}.abc PATTERN "([0-9][0-9] .)" TO "{filepath$|..}{file$|noext}\\1" REGEXP

[quote="Xyzzy"]
The problem is, that when multiple files are selected, it works only for the last file (apparently cd doesn't work as expected in such a case).[/quote]
To be precise, for the other files program.exe reports File not found.

As an aside, you'll probably want to add @nofilenamequoting and then put explicit quotes around the places using {filepath} or {file} which aren't already quoted. The automatic quoting is likely to not handle all the cases being thrown at it there, and you've got explicit quotes in some places but not others, so it makes sense to turn off automatic quoting and make all the quotes explicit.

With that out the way, things when Opus generates the command, lines that reference a single file will be repeated for each of the selected files. But they are repeated before moving to the next line. It doesn't run the whole button on one file before moving to the next file; it runs each line for each file, then the next line, and so on.

If the program has to work on the current directory and cannot be given the full path to a file, you may be able to work around it using a user-command. I would probably use a batch file or script instead, as it's easier. You could pass the batch file the path and filename and it could do the CD and run the program on the file:

@codepage:852
CreateFolder {filepath$|..}{file$|noext}
MyBatchFile.bat {filepath$|..} {file$}
Rename FROM {filepath$|..}.abc PATTERN "([0-9][0-9] .)" TO "{filepath$|..}{file$|noext}\\1" REGEXP

So please add a feature to have a button actually run once for each file as a whole, if there are no codes present that suggest otherwise.

BTW, I tried to circumvent the current behaviour with
cd {filepath$|..} & C:\Programy\program.exe -c {file$}
but it did not work (not to mention that Rename would work for the last file only, but I could create another button to handle this en masse.

We have something planned which will address this, in the medium term.

Using & to run multiple commands on a single line will not work in a normal (non MS-DOS Batch button), as that is an MS-DOSism. It might work with a DOS button.

Not sure what you mean about the rename command only working on the last file. It would be run on all files. All of the commands are run on all files, the only issue here is the order they are run in.

[quote="leo"]
Not sure what you mean about the rename command only working on the last file. It would be run on all files. All of the commands are run on all files, the only issue here is the order they are run in.[/quote]

You are right.

Thanks for all the explanations.