Page 1 of 1

Batch New Items

Posted: 29 Sep 2008 17:41
by jacky
Just a little script to easily create a bunch of new files or folders by specifying a list of names...

Note that again, a file tmp.ini (in the script's folder) will be used, and removed. So if you already use such a thing and don't want it to be gone, make the necessary adjustments.
Also, you will need to switch recursion checker off or you'll get a lot of warnings...

Code: Select all

"Batch New Items... : BatchNewItems"
	// files or folders ?
	$is_file = confirm("Do you want to create files, or folders ?<br><br>OK = Files<br>Cancel = Folders","<br>");
	// ask for new items' names
	input $names, "Enter new ".(($is_file) ? "files" : "folders")."' names", <clipboard>, m;
 	// get last 2 bytes
	substr $check, $names, -2;
	// and make sure it ends with a CRLF
	$names = $names . (($check == <crlf>) ? "" : <crlf>);
	// switch to one-line
	replace $names, $names, <crlf>, "|";
	// and store names
	setkey $names, "Names", "BatchNewItems", "tmp.ini";
	// store type
	setkey $is_file, "IsFile", "BatchNewItems", "tmp.ini";
	// start creating loop if something to do
	sub ($names == "|") ? "_bniNothing" : "_bniLoop";
"_bniNothing"
	sub _delTmpIni;
	status "No name specified",,stop;
"_bniLoop"
	// get type
	getkey $is_file, "IsFile", "BatchNewItems", "tmp.ini";
	// get list of names
	getkey $names, "Names", "BatchNewItems", "tmp.ini";
	// search for the first item
	strpos $pos, $names, "|";
	// and "extract" it
	substr $name, $names, 0, $pos;
	
	// remove item from list of names
	substr $names, $names, $pos + 1;
	// saves new list
	setkey $names, "Names", "BatchNewItems", "tmp.ini";
	
	// script to create the new file/folder
	$script = 'new "'.$name.'", '.(($is_file) ? 'file' : 'dir').';';
	// create item if there's a name
	load (($name == "") ? 'incr $void;' : $script),,s;
	
	// we only continue if there is another name
	sub ($names == "") ? "_delTmpIni" : "_bniLoop";
"_delTmpIni"
	setkey 1, "FileExists", "Ensure", "tmp.ini";
	self $path, path;
	delete 0, 0, "$path\tmp.ini";

Re: Batch New Items

Posted: 02 Oct 2008 04:26
by lukescammell
I've not tried this yet, but...

To save any possible problems with tmp.ini overwriting someone else's tmp.ini, shouldn't you just namespace temp files for each script? Like call it, BatchNewItemsTmp.ini or something?