Page 2 of 3

Re: create folder based on the filename

Posted: 01 Nov 2011 10:20
by highend

Code: Select all

"Create folder(s) from selected file(s) / clipboard"
   ;

"... from clipboard"
   // Check if a name contains a "\" (Item Path/Name(s) was used
   set $SelectedItems, <clipboard>;
   foreach($Item, $SelectedItems, "<crlf>") {
      if($Item == ""){ break; }
      if(strpos($Item, "\", 0, 1) != "-1"){
         $Path = regexreplace($Item, "(.*\\)(.*)", "$1");
         $ItemName = replace("$Item", "$Path");
         $ItemName = regexreplace($ItemName, "(.+(?=\.))(.+)", "$1");
         new($ItemName, dir);
         new($ItemName.".txt");
      } else {
         $ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
         new($ItemName, dir);
         new($ItemName.".txt");
      }
   }

"... from selected file(s)"

   $SelectedItems = get("SelectedItemsNames", "|");
   foreach($Item, $SelectedItems, "|") {
      $ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
      new($ItemName, dir);
      new($ItemName.".txt");
   }

Re: create folder based on the filename

Posted: 01 Nov 2011 12:31
by kotlmg
thanks a lot sir, the above script works. is it possible to add the option folder or text file name with the above code?

Re: create folder based on the filename

Posted: 01 Nov 2011 13:19
by highend
Did you even take a look at the script?

Code: Select all

new($ItemName.".txt");
3 x times...

Re: create folder based on the filename

Posted: 01 Nov 2011 14:19
by kotlmg
before posting my query, i have thoroughly seen your code sir. by default it creates folder and text file. if possible please create folder or text file depending upon the user selection.
thanks a lot.

Re: create folder based on the filename

Posted: 01 Nov 2011 14:34
by highend
One by one or for all (selected items / clipboard entries)?

Re: create folder based on the filename

Posted: 01 Nov 2011 14:42
by kotlmg
for all selected items/clipboard entries

Re: create folder based on the filename

Posted: 01 Nov 2011 15:13
by highend

Code: Select all

"Create folder(s) from selected file(s) / clipboard"
   ;

"... from clipboard"
   $Process = confirm("If you want to create folders, hit 'OK'.<br>"Cancel" will create .txt files instead.");
   // Check if a name contains a "\" (Item Path/Name(s) was used
   set $SelectedItems, <clipboard>;
   foreach($Item, $SelectedItems, "<crlf>") {
      if($Item == ""){ break; }
      if(strpos($Item, "\", 0, 1) != "-1"){
         $Path = regexreplace($Item, "(.*\\)(.*)", "$1");
         $ItemName = replace("$Item", "$Path");
         $ItemName = regexreplace($ItemName, "(.+(?=\.))(.+)", "$1");
         if($Process == 1){
         	new($ItemName, dir)
         } else {
         	new($ItemName.".txt");
         }
      } else {
         $ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
         new($ItemName, dir);
         new($ItemName.".txt");
      }
   }

"... from selected file(s)"
   $Process = confirm("If you want to create folders, hit 'OK'.<br>"Cancel" will create .txt files instead.");
   $SelectedItems = get("SelectedItemsNames", "|");
   foreach($Item, $SelectedItems, "|") {
      $ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
      if($Process == 1){
         new($ItemName, dir)
      } else {
         new($ItemName.".txt");
      }
   }

Re: create folder based on the filename

Posted: 01 Nov 2011 15:26
by kotlmg
thanks a lot sir. my requirements are fully satisfied. once again thanks a lot sir.

Re: create folder based on the filename

Posted: 03 Nov 2011 12:28
by kotlmg
sir to the above code is it possible to add create
folder or text file or one of the (.sub/.idx/.srt/.sup/.ssa/.smi) depending on user selection.

thanks a lot in advance.

Re: create folder based on the filename

Posted: 03 Nov 2011 13:03
by highend

Code: Select all

/* 03.11.2011, Create files or folders from selected files / clipboard entries
   ::load "<xyscripts>\.snippets\CreateFilesOrFolders.xys";
*/

	$Formats = "folder|.txt|.sub|.idx|.srt|.sup|.ssa|.smi";
	$OutputFormat = inputselect("Select your destination format", "$Formats", "|", 4);
	$FilesOrClipboard = confirm("Click OK to use your selected files.#Cancel to use clipboard entries.", "#");

	if($FilesOrClipboard == 1){
		$SelectedItems = get("SelectedItemsNames", "|");
		foreach($Item, $SelectedItems, "|") {
			$ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
			if($OutputFormat == folder){
				new($ItemName, dir)
			} else {
				new($ItemName."$OutputFormat");
			}
		}
	} else {
		// Check if a name contains a "\" (Item Path/Name(s) was used
		set $SelectedItems, <clipboard>;
		foreach($Item, $SelectedItems, "<crlf>") {
			if($Item == ""){ break; }
			if(strpos($Item, "\", 0, 1) != "-1"){
				$Path = regexreplace($Item, "(.*\\)(.*)", "$1");
				$ItemName = replace("$Item", "$Path");
				$ItemName = regexreplace($ItemName, "(.+(?=\.))(.+)", "$1");
				if($OutputFormat == folder){
					new($ItemName, dir)
				} else {
					new($ItemName."$OutputFormat");
				}
			} else {
				$ItemName = regexreplace($Item, "(.+(?=\.))(.+)", "$1");
				if($OutputFormat == folder){
					new($ItemName, dir);
				} else {
					new($ItemName.".txt");
				}
			}
		}
	}

Re: create folder based on the filename

Posted: 03 Nov 2011 13:15
by kotlmg
wonderful sir. the code is perfectly working.
thanks a lot once again.

Re: create folder based on the filename

Posted: 13 Nov 2011 06:46
by kotlmg
hello sir,
to the above code can you please add the option of select destination folder either by typing the path or selecting the path. right now the above script is allowing the user to select path by browsing. i want to type the folder path. can you please add the above option pleaase?

Re: create folder based on the filename

Posted: 13 Nov 2011 08:10
by j_c_hallgren
kotlmg wrote:hello sir,
to the above code can you please add the option of select destination folder either by typing the path or selecting the path. right now the above script is allowing the user to select path by browsing. i want to type the folder path. can you please add the above option pleaase?
Oh come on.... :roll: Did you ever think about trying to write these code changes YOURSELF? Esp since you previously wrote (emphasis added):
kotlmg wrote:thanks a lot sir. my requirements are fully satisfied. once again thanks a lot sir.
I'm not a XY scripter (though I've programmed in other languages for 25+ yrs) but I know that some who are do get rather irritated and frustrated by users who keep asking for this and that little change to be coded and never try to learn enough to attempt those changes themselves...there are enough examples found here in forums that should be able to help a new coder, I think.

Re: create folder based on the filename

Posted: 13 Nov 2011 10:45
by kotlmg
nowadays, your forum started giving sarcastic replies to the users. this may not be good for you and your product. you should try to guide, not to give sarcastic comments. thanks for your not coding.

Re: create folder based on the filename

Posted: 13 Nov 2011 10:56
by PeterH
kotlmg wrote:nowadays, your forum started giving sarcastic replies to the users. this may not be good for you and your product. you should try to guide, not to give sarcastic comments. thanks for your not coding.
Thanks for not understanding.

And by the way: it's not his forum. And not his product.
He only likes both.