Author Topic: Work with a target path  (Read 33659 times)

pncdaspropagandas

  • Contributor
  • Active Member
  • *****
  • Posts: 93
    • View Profile
Work with a target path
« on: September 05, 2017, 18:20:02 »
If you have to move/copy files from various places to a specific folder, or if you are going to do a lot of fractioned operations, here is some cool scripts:

Define a target folder/path:
Code: [Select]
@var $target_path = GetSourcePath();
@var $target_path_temp_file = ".\\Config\\UserDefinedScripts\\File Ops\\target_path.txt";
SaveStringToFile($target_path_temp_file, $target_path, 0);
MessageBox("Target defined", $target_path, 0);

Show a MessageBox with stored folder:
Code: [Select]
@var $target_path_temp_file = ".\\Config\\UserDefinedScripts\\File Ops\\target_path.txt";
if( !(FileExists($target_path_temp_file)) )
{
MessageBox( "Show Target", "No target path defined yet.", 0);
break;
}
@var $target_path = LoadStringFromFile($target_path_temp_file);
MessageBox("Show Target", $target_path, 0);

Go To target Folder:
Code: [Select]
@var $target_path_temp_file = ".\\Config\\UserDefinedScripts\\File Ops\\target_path.txt";
if( !(FileExists($target_path_temp_file)) )
{
MessageBox( "Show Target", "No target path defined yet.", 0);
break;
}
@var $target_path = LoadStringFromFile($target_path_temp_file);
MC.Explorer.Goto SOURCE={$target_path}

Copy Selected File/Folders to Target:
Code: [Select]
//
//
// For some reason, when using USEEXISTINGQUEUE, it fails to OVERWRITE, so I always use NEWQUEUE
//
//

@var $target_path_temp_file = ".\\Config\\UserDefinedScripts\\File Ops\\target_path.txt";
if( !(FileExists($target_path_temp_file)) )
{
MessageBox( "Copy to Target", "No target path defined yet.", 0);
break;
}
@var $target_path = LoadStringFromFile($target_path_temp_file);

@var $arr_selected_items[] = GetSourceSelectedPaths();

@var $n;
@var $options = {"Overwrite", "Overwrite All", "Ignore", "Abort"};
@var $user_option = -2;
@var $n_file;
if( arrayCount($arr_selected_items) >= 1 )
{
for ($n=0; $n < arrayCount($arr_selected_items); $n++)
{
// Overwrite All
if( $user_option == 1 )
{
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
CopyFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
CopyFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//CopyFileMLR($target_path, $arr_selected_items[$n], $n);
}
else
{
$n_file = PathGetNamePart($arr_selected_items[$n], 0);
if( FileExists($target_path ^ $n_file) )
{
$user_option = AskOption('File/Folder "' + $n_file + '" already exists on target.', $options, 0);
if( $user_option == 0 )
{
// Overwrite
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
CopyFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
CopyFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//CopyFileMLR($target_path, $arr_selected_items[$n], $n);
}
else if( $user_option == 1 )
{
// Overwrite All
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
CopyFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
CopyFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//CopyFileMLR($target_path, $arr_selected_items[$n], $n);
}
else if( $user_option == 3 )
{
// Abort
$n = arrayCount($arr_selected_items) + 1;
}
}
else
{
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
CopyFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
CopyFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//CopyFileMLR($target_path, $arr_selected_items[$n], $n);
}
}
}
}

Move File/Folders to Target:
Code: [Select]
//
//
// For some reason, when using USEEXISTINGQUEUE, it fails to OVERWRITE, so I always use NEWQUEUE
//
//

@var $target_path_temp_file = ".\\Config\\UserDefinedScripts\\File Ops\\target_path.txt";
if( !(FileExists($target_path_temp_file)) )
{
MessageBox( "Copy to Target", "No target path defined yet.", 0);
break;
}
@var $target_path = LoadStringFromFile($target_path_temp_file);

@var $arr_selected_items[] = GetSourceSelectedPaths();

@var $n;
@var $options = {"Overwrite", "Overwrite All", "Ignore", "Abort"};
@var $user_option = -2;
@var $n_file;
if( arrayCount($arr_selected_items) >= 1 )
{
for ($n=0; $n < arrayCount($arr_selected_items); $n++)
{
// Overwrite All
if( $user_option == 1 )
{
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
MoveFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
MoveFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//MoveFileMLR($target_path, $arr_selected_items[$n], $n);
}
else
{
$n_file = PathGetNamePart($arr_selected_items[$n], 0);
if( FileExists($target_path ^ $n_file) )
{
$user_option = AskOption('File/Folder "' + $n_file + '" already exists on target.', $options, 0);
if( $user_option == 0 )
{
// Overwrite
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
MoveFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
MoveFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//MoveFileMLR($target_path, $arr_selected_items[$n], $n);
}
else if( $user_option == 1 )
{
// Overwrite All
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
MoveFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
MoveFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//MoveFileMLR($target_path, $arr_selected_items[$n], $n);
}
else if( $user_option == 3 )
{
// Abort
$n = arrayCount($arr_selected_items) + 1;
}
}
else
{
if ( IsFolder($arr_selected_items[$n]) )
{
// Add / to source path
MoveFile($target_path, $arr_selected_items[$n] + "\\", "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
else
{
MoveFile($target_path, $arr_selected_items[$n], "NODIALOG, NOPROGRESS, OVERWRITE_ALL, NEWQUEUE");
}
//MoveFileMLR($target_path, $arr_selected_items[$n], $n);
}
}
}
}