Hi there,
I am trying to write a script to automate a task where a selection of files is processed using a DOS based command. I have managed to get one file processed at a time using my script but when I run it (from the catalog) on multiple items only one is processed. My script does this:
::run "dbtran" "-p z32" "<curitem>"
It doesn't matter if I set the properties of the catalog item to single instance or multiple instance the results are the same. I feel like I am missing something obvious! Can anyone point me in the right direction please?
thanks,
Ach
Processing files using Scripting
-
acheton
- Posts: 293
- Joined: 27 Jul 2010 23:58
- Location: XY 64bit, Win 11 at 100%
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Processing files using Scripting
<curitem> ist only for the selected / focused item. If you want to process all selected items (in one commandline!) you could use <selitems>.
If every selected items has to be passed as the only fileparameter to your dos command you have to use a while loop or better foreach but be warned, they would all open at (nearly) the same time (so your screen can be flooded with command prompts) *g*
The only good way to use dos commands with only one file to process at a time and executed after another is to use a foreach loop and write a (temporary) batch file and execute it after it has been written.
Something like this:
If every selected items has to be passed as the only fileparameter to your dos command you have to use a while loop or better foreach but be warned, they would all open at (nearly) the same time (so your screen can be flooded with command prompts) *g*
The only good way to use dos commands with only one file to process at a time and executed after another is to use a foreach loop and write a (temporary) batch file and execute it after it has been written.
Something like this:
Code: Select all
foreach($Token, $SelectedItems, "|") {
$FileBase = gettoken($Token,1,"?");
$FileExtOld = gettoken($Token,2,"?");
$FileNameOld = "$FileBase.$FileExtOld";
$FileNameNew = "$FileBase.$FileExtNew";
$InputFile = "$InputPath\$FileNameOld";
$OutputFile = "$OutputPath\$FileNameNew";
$ReturnCode = exists("$OutputFile");
if ($ReturnCode == 1) {
delete 1, 0, "$OutputFile";
}
if($FileExtNew == "") {
writefile($TempFile, CALL $Sox_Cmd $gopts "$InputFile".<crlf>, a, ta);
writefile($TempFile, pause.<crlf>, a, ta);
}
else {
writefile($TempFile, CALL $Sox_Cmd $gopts "$InputFile" $fopts "$OutputFile" $effopt.<crlf>, a, ta);
}
}
open "$TempFile";One of my scripts helped you out? Please donate via Paypal
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: Processing files using Scripting
Maybe something like:acheton wrote:I have managed to get one file processed at a time using my script but when I run it on multiple items only one is processed. My script does this:
::run "dbtran" "-p z32" "<curitem>"
Code: Select all
//////Collect selected files into an var:
$files = get("SelectedItemsPathNames","<crlf>");
//////For Each File In Files Do:
foreach( $file, $files, "<crlf>")
{
run "C:\windows\notepad" "$file",,1;
msg "proceed?",1;
status Processing $file;
}
//////At the end inform the user:
status "All done!";
beep 200, 600; beep 300, 100;
text "All done:<crlf>$files";
Code: Select all
Syntax run()
run command, [directory], [wait=0]
command
Anything that works in Windows Start | Run
[directory]
The working directory, allows you to skip the path in command; defaults to current path.
[wait]
0: [default] return immediately and continue the script
1: only continue when the shelled process has finished;
Note: if something doesn't work as expected, often it belongs to wrong used quotes ""
See there for some examples >>> http://www.xyplorer.com/xyfc/viewtopic. ... 438#p60438
-
acheton
- Posts: 293
- Joined: 27 Jul 2010 23:58
- Location: XY 64bit, Win 11 at 100%
Re: Processing files using Scripting
Thanks for the help guys that was very helpful. It is now working a treat. I also realised I could do a for loop in DOS by entering ! following by a DOS command into the address bar...
XYplorer Beta Club