create folder based on the filename

Discuss and share scripts and script files...
highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: create folder based on the filename

Post 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");
   }
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post 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?

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: create folder based on the filename

Post by highend »

Did you even take a look at the script?

Code: Select all

new($ItemName.".txt");
3 x times...
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post 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.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: create folder based on the filename

Post by highend »

One by one or for all (selected items / clipboard entries)?
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post by kotlmg »

for all selected items/clipboard entries

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: create folder based on the filename

Post 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");
      }
   }
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post by kotlmg »

thanks a lot sir. my requirements are fully satisfied. once again thanks a lot sir.

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post 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.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: create folder based on the filename

Post 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");
				}
			}
		}
	}
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post by kotlmg »

wonderful sir. the code is perfectly working.
thanks a lot once again.

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post 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?

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: create folder based on the filename

Post 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.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

kotlmg
Posts: 321
Joined: 30 Jun 2010 17:14

Re: create folder based on the filename

Post 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.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: create folder based on the filename

Post 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.

Post Reply