Code: Select all
/* Script to copy each selected file to a new folder named after the file.
Example: if file name is "hello.ext", a folder called "hello" is created then
the file is copied inside the folder. Name collisions will hopefully be handled
from the "new" scripting command wich is used.
Tested with XYplorer v7.90.0120 and v7.90.0125 beta */
// We collect the informations needed to operate
"start"
setting "AllowRecursion";
global $counter;
global $items_number;
global $items_data;
$counter = 0;
$items_number = getinfo(CountSelected);
$items_data = report({Name}|{Ext}|{Fullname}|{Dir 1|2|3}<crlf>, 1);
sub "_emptyselection_check";
// If selection is empty, the script will end
"_emptyselection_check"
global $items_number;
$emptyselection_truth = ("$items_number" == "0") ? "_emptyselection_exit" : "_main_check";
sub "$emptyselection_truth";
// We need to loop until there are items to be processed then end execution
"_main_check"
global $counter;
global $items_number;
incr $counter;
status "Processing data...", , progress;
$more_items_check = ("$counter" <= "$items_number") ? "_go_on" : "_done_exit";
sub "$more_items_check";
// Check to see if the item is a file and need to be processed or a folder and
// thus need to be skipped
"_go_on"
global $counter;
global $items_data;
global $item_being_processed;
$item_being_processed = gettoken("$items_data", $counter, "<crlf>");
$file_check = gettoken("$item_being_processed", 4, "|");
$file_check_truth = ("$file_check" != "2") ? "_main_check" : "_file_action";
sub "$file_check_truth";
// A file may not have an extension. If present we'll drop it later, if not the
// file can be processed as it is
"_file_action"
global $item_being_processed;
global $file_name;
global $file_ext;
global $file_base;
$file_name = gettoken("$item_being_processed", 1, "|");
$file_ext = gettoken("$item_being_processed", 2, "|");
$file_base = "$file_name";
$file_ext_truth = ("$file_ext" != "") ? "_drop_extension" : "_create_dir";
sub "$file_ext_truth";
// We drop the extension because if file name is "hello.ext", we would like to
// simply call the folder "hello"
"_drop_extension"
global $file_name;
global $file_ext;
global $file_base;
strlen $file_name_lenght, "$file_name";
strlen $file_ext_lenght, "$file_ext";
substr $file_base, "$file_name", 0, ($file_name_lenght - $file_ext_lenght - 1);
sub "_create_dir";
// Finally a folder can be created
"_create_dir"
global $file_base;
global $created_dir;
new "$file_base", dir;
$created_dir = "<curname>";
sub "_copy_file";
// Let's copy the file
"_copy_file"
global $item_being_processed;
global $created_dir;
$file_fullname = gettoken("$item_being_processed", 3, "|");
copyto "$created_dir", "$file_fullname";
sub "_main_check";
// End execution because selection was empty
"_emptyselection_exit"
status "Please select one or more files", , stop;
// End execution
"_done_exit"
status "Done";