Multi Commander > User Contributed Content
Create an empty file
(1/1)
pncdaspropagandas:
This scripts creates an empty file (if provided name is not already a file) and defaults to .txt if extension is not typed. Selects the file after that.
--- Code: ---// Ask user for file name
@var $answer = AskText("Enter file name", "New file.txt", 0);
// If user canceled, abort
if ( $answer == 0 )
{
break;
}
// Full path name
@var $file_name = GetSourcePath() ^ $answer;
// If answer doesn't have any extension, default to .txt
@var $ext_size = StrLen( PathGetFileExtPart($file_name) );
if ($ext_size == 0)
{
$file_name = $file_name + ".txt";
}
// File exists?
if (FileExists($file_name) > 0)
{
MessageBox("Error", "File already exists", 0);
}
else
{
// Create empty file
SaveStringToFile($file_name, "", 0);
// It's not possible to select the created file because the script doesn't recognize new items until the script ends. Only when it finishes is that new items are available and refreshed.
// But found a way using native CTRL+V feature
SetClipboardText($file_name);
MC.Explorer.Selection.UnselectAll
MC.RunCmd ID="Core.1312"
}
--- End code ---
Mathias (Author):
You can type "cf <filename>" (without ") in the commandline field to create a file..
cf myfile.txt
and the 0byte file named myfile.txt is created in the panel that are in focus
pncdaspropagandas:
Good point. Thanks
pncdaspropagandas:
I added the possibility to create multiple empty files at once, just like folder creation where you write folders separated by semi-colon:
--- Code: ---@var $n;
@var $file;
@var $file_name;
// Ask user for file name
@var $answer = AskText("Enter file name", "New file.txt", 0);
// If user canceled, abort
if ( $answer == 0 )
{
break;
}
@var $arr_files = StrTokenize2Array($answer, ";");
for( $n=0; $n<arrayCount($arr_files); $n++ )
{
$file = $arr_files[$n];
// Full path name
$file_name = GetSourcePath() ^ $file;
// If answer doesn't have any extension, default to .txt
@var $ext_size = StrLen( PathGetFileExtPart($file_name) );
if ($ext_size == 0)
{
$file_name = $file_name + ".txt";
}
// File exists?
if (FileExists($file_name) > 0)
{
MessageBox("Error", "File already exists. Stopping script.", 0);
break;
}
else
{
// Create empty file
SaveStringToFile($file_name, "", 0);
}
}
// Select created file
if( arrayCount($arr_files) == 1 )
{
// It's not possible to select the created file because the script doesn't recognize new items until the script ends. Only when it finishes is that new items are available and refreshed.
// But found a way using native CTRL+V feature
SetClipboardText($file_name);
MC.Explorer.Selection.UnselectAll
MC.RunCmd ID="Core.1312"
}
--- End code ---
Navigation
[0] Message Index
Go to full version