BatMaker - BatchMaker - BatchCreator
Posted: 16 Dec 2009 10:42
In the past i have collected names of files, paste them in an texteditor, modified the line and saved it as batch CMD.
I have seen this could be automatic by an feature in other FM and as stand alone tool also.
Now i tried to do the same with the help of an XYplorer script, just for the need and the joy.
First i have used
but with the friendly help of Don i can do this much simpler now with 'report'
The main part of this script is the script "report"-command,
(see XYplorer Help file > Advanced Topics > Scripting Commands Reference > report)
All i have done is to wrote an script to use the "report" -feature with one click.
(If one of you wants to help to improve the text in the GUI or in the script description... please comment below {english isn't my first language}
)
The first try:
I have seen this could be automatic by an feature in other FM and as stand alone tool also.
Now i tried to do the same with the help of an XYplorer script, just for the need and the joy.
First i have used
Code: Select all
$filelist = getinfo('SelectedItemsPathNames', '|');
$file=gettoken($filelist, 1, "|");
$Path = regexreplace($file, "(.+)\\.+", "$1");
$Name = regexreplace($file, ".+\\(.+)\..*", "$1");
$Exte = regexreplace($file, ".+\.(.*)", "$1");The main part of this script is the script "report"-command,
(see XYplorer Help file > Advanced Topics > Scripting Commands Reference > report)
All i have done is to wrote an script to use the "report" -feature with one click.
(If one of you wants to help to improve the text in the GUI or in the script description... please comment below {english isn't my first language}
Code: Select all
/*
BatMaker_20091215.xys , Stefan
LICENSE:
This script is free software: you can redistribute and/or modify it.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If your computer implode or your files gets lose, don't blame me, so
please try this script first with some test files in an virtual machine.
Purpose:
Script to create an text file with an collection of all seleted files
and with common prefix and suffix for each line.
How to use:
1. Select a few files
2. run this script
3. modify the output line with placeholders and literal text
4. press OK and you will see an text with all selected files, incl. all expanded placeholders and your literal text
*/
//Version Check - Needs the latest XYplorer BETA version (v8.70.0150, 15-dec-2009) or newer
$MIN_VERSION = "8.70.0150";
End(Compare("$MIN_VERSION", "<xyver>", "v") > 0, "You need at least version $MIN_VERSION of XYplorer for this script.");
// the script:
End ("<curitem>"==""), "No file selected!"; //check if any file is selected
End (strpos("<curitem>", ".")<0), "Only files please";
$Desc = "Manual: ";
$Desc = $Desc . "<crlf> Creates an text with one line for each selected file with common pre- and sufix.";
$Desc = $Desc . "<crlf> Use this e.g. to create DOS batch files.";
$Desc = $Desc . "<crlf><crlf>You can use this pattern to build the output lines:";
$Desc = $Desc . "<crlf> #F = path\name.ext<crlf> #P = Path only<crlf> #N = Name<crlf> #E = Extension";
$Desc = $Desc . "<crlf><crlf>Batch examples:<crlf> ""REN #F #P\#N-backup.#E""";
$Desc = $Desc . "<crlf> ""COPY #F .""";
$Desc = $Desc . "<crlf>Other examples:<crlf> ""#F"" or ""#N.#E"", create just an list of names";
$Desc = $Desc . "<crlf><crlf>Hint:<crlf> This # -tokens are internal replaced with XY-script tokens.";
$Desc = $Desc . "<crlf> Read XYplorer help > ""Scripting Commands Reference > Report"" for more tokens.";
$Desc = $Desc . "<crlf> Example: ""{name}, {size KBR}, {Created yyyymmdd}""";
$Input = Input("BatMaker", $Desc, "REN #F #P\#N_bak.#E");
//convert user-friendly placeholders to XY tokens:
replace $out1, $Input, "#F", "{fullname}";
replace $out2, $out1, "#P", "{fullpath}";
replace $out1, $out2, "#N", "{basename}";
replace $output, $out1, "#E", "{ext}";
//text report($output . "<crlf>",1);
writefile("%tmp%\xydata.txt", report($output . "<crlf>",1), o);
run Notepad "%tmp%\xydata.txt";
The first try:
Code: Select all
/*
BatMaker 20091212 , Stefan
LICENSE:
This script is free software: you can redistribute and/or modify it.
This script is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If your computer implode or your files gets lose, don't blame me, so
please try this script first with some test files in an virtual machine.
Purpose:
Script to create an text file with an collection of all seleted files
and with common prefix and suffix for each line.
How to use:
*/
// the script:
End ("<curitem>"==""), "No file selected!"; //check if any file is selected
End (strpos("<curitem>", ".")<0), "Only files please";
$Desc = "BatMaker: ";
$Desc = $Desc . "<crlf>Creates an text with one line for each selected file with common pre- and sufix.";
$Desc = $Desc . "<crlf>Use this e.g. to create DOS batch files.";
$Desc = $Desc . "<crlf><crlf>You can use this pattern to build the lines:";
$Desc = $Desc . "<crlf>#P = Path only<crlf>#F = path\name.ext<crlf>#N = Name<crlf>#E = Extension";
$Desc = $Desc . "<crlf><crlf>Example: ""REN #F #P\#N-backup.#E.bak"" |>> rename files";
$Desc = $Desc . "<crlf>Example: ""COPY #F ."" |>> copy files to current folder";
$Desc = $Desc . "<crlf>Example: ""#F"" or ""#N.#E"" |>> create just an list of names";
$Input = Input("Prefix", $Desc, "REN #F #P\#N-backup.#E.bak");
$filelist = getinfo('SelectedItemsPathNames', '|');
$file=gettoken($filelist, 1, "|");
$Path = regexreplace($file, "(.+)\\.+", "$1");
$BatOutput = "";
$count = 1;
while(1)
{
$file=gettoken($filelist,$count,"|");
if("$file"==""){break;}
$Name = regexreplace($file, ".+\\(.+)\..*", "$1");
$Exte = regexreplace($file, ".+\.(.*)", "$1");
$Output = regexreplace($Input, "#P", $Path);
$Output2 = regexreplace($Output, "#F", $file);
$Output = regexreplace($Output2, "#N", $Name);
$Output = regexreplace($Output, "#E", $Exte);
$BatOutput = $BatOutput . $Output<crlf>;
$count++;
}
text $BatOutput;