AutoHotkey: Dummy File Creator

Discuss and share scripts and script files...
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

AutoHotkey: Dummy File Creator

Post by Stefan »

Dummy File Creator

Since i can't do this with XYScripting right now (v7.80) i have dust off an old Autohotkey script for that issue.

EDIT:
jacky show me kindly how one could to this with XYScripting:
DummyFileCreator.xys

Code: Select all

msg "This script will create new text files from an list in the clipboard.<br>Do want to continue?",1;
  //test content $clip = "Name1.txt"<crlf>"Name2.txt"<crlf>"Name3.txt"; 
  $clip = <clipboard>; //or input list from file
  substr $check, $clip, -2;
  $script = $clip . (($check == <crlf>) ? "" : <crlf>);
  msg "Currently in clipboard:<br>------<br>" . $script . "<br>------<br>Do you want to create this list as empty text files?" ,1;
  regexreplace $script, $script, "^(.+?)\r\n", 'new "$1"; ';  
  load $script,,s;
Thank you jacky.
/EDIT

Code: Select all

Dummy File Creator 	version .05,   Nov. 2008 by Stefan
	(OpenSource, No warranty, use on your own risk.)
	
	Creates new empty text files, f.ex. for testing issues.	
	
	F.ex. 
	if you want to help an user at an forum with renaming issues,
	copy the example file names this user has posted to the clipboard.
	Then go to an temp folder and execute this tool and follow the dialogs.
	This way you will get empty text files with names found on the clipboard.
	Note: 
	the files are created in the current folder where the DummyFileCreator.exe is in,
	but accept an path to create the files as commandline parameter also.
	
		
	1.) Download DummyFileCreator.exe and put it in 'Tools'-sub-folder in <xypath>
	
	2.) User > Manage Commands
	Action: Open
	[New]
	Caption: Dummy File Creator (from list of file names at the clipboard)
	Item: 	"Tools\DummyFileCreator.exe"  "<curpath>"
	[OK]
	

	If you want to execute this tool with an shortcut:
        3.) Tools > Costumize Shortcuts		
	Category: Open
	Commands: Dummy File Creator (from list of file names at the clipboard)
	Shortcut: Click on [All Free Shortcuts...] an pick one you like, 
            then give 'Press new shortcut:' the focus and press this shortcut-keys
	[Assign]
	[OK]
DummyFileCreator.zip
Then copy f.ex. this file names to the clipboard:
Krokus - Eat the rich.mp6
Lynyrd Skynyrd - Free Bird.mp6
Manowar - Heart of steel.mp6
Meat Loaf - Bat out of Hell.mp6
Metallica - Am I Evil_.mp6

Then go to an temp folder and execute the DummyFileCreator





AutoHotkey source code

Code: Select all

#NoTrayIcon
#SingleInstance force

; AHK_FileCreater, creates new files with names from a list, e.g. from MyMusic.m3u
; usefull to create quickly a few dummy files, e.g. for FileRenamer tests issue

If %0% > 0
vWorkingDir = %1%
Else
vWorkingDir = %A_WorkingDir%   ;use the standard workingdir where this script/exe is too


Msg1 = Create empty text files for testing issues:`n
Msg1 = %Msg1%1.) Copy an list of file names to the clipboard. (Every name on its own line. And only strings, not real files itself)`n
Msg1 = %Msg1%2.) Then execute this script which creates empty dummy files in the current folder:`n%vWorkingDir%`n`n
Msg1 = %Msg1%This is currently in the clipboard and would be treated as file name:`n`n%Clipboard%`n`n
Msg1 = %Msg1%-------------------------------------`nDo you want to create this files?
MsgBox,1, Dummy File Creator, %Msg1%
	   IfMsgBox Cancel
       Exit App
       
       
Loop, parse, clipboard, `n, `r
{
	vFileName = %A_LoopField%
	;vFileName = remove non-valid chars
  IfExist, %vWorkingDir%\%vFileName%   
	 continue  ;Don't overwrite existing files

If (DOntAskAgain <> 1) Then
	{
	MsgBox2 = Create this file?:`n`n%vWorkingDir%\`n%vFileName%`n`n`n
	MsgBox2 = %MsgBox2%Press [OK] to creating this file`n
	MsgBox2 = %MsgBox2%Press [No] to don't ask again and create all`n
	MsgBox2 = %MsgBox2%Press [Cancel] to aboard the script and end
  MsgBox, 3, Question ,%MsgBox2%
	   IfMsgBox Cancel
       return
     IfMsgBox No
       DOntAskAgain=1
   }

;create the file:
  FileAppend,Dummy File Creator v0.4 by Stefan 2005-2008`, www.AutoHotkey.com, %vWorkingDir%\%vFileName%
}

MsgBox,64,Dummy File Creator, Finished`, all done.
Exit App
For more info about AHK scripting go to http://www.autohotkey.com
You do not have the required permissions to view the files attached to this post.
Last edited by Stefan on 27 Nov 2008 15:09, edited 3 times in total.

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: AutoHotkey: Dummy File Creator

Post by jacky »

Stefan wrote:Since i can't do this with XYScripting right now (v7.80) i have dust off an old Autohotkey script for that issue.
Why? Did you even looked at what commands are available, like "new" to create new files/folders ? There's no reason you can't create new files from scripting!

Here's a very basic script to create files from names in the clipboard:

Code: Select all

  regexreplace $script, <clipboard>, "^(.+?)\r\n", 'new "$1"; ';
  load $script,,s;
Proud XYplorer Fanatic

admin
Site Admin
Posts: 66083
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: AutoHotkey: Dummy File Creator

Post by admin »

jacky wrote:
Stefan wrote:Since i can't do this with XYScripting right now (v7.80) i have dust off an old Autohotkey script for that issue.
Why? Did you even looked at what commands are available, like "new" to create new files/folders ? There's no reason you can't create new files from scripting!

Here's a very basic script to create files from names in the clipboard:

Code: Select all

  regexreplace $script, <clipboard>, "^(.+?)\r\n", 'new "$1"; ';
  load $script,,s;
Très elegant, monsieur!

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

Re: AutoHotkey: Dummy File Creator

Post by PeterH »

jacky, I admire your scripting. 2 lines, and that's it - really great.

But I have "programmed" in maybe 10 "languages" - and now have no interest to learn more, especially reg expressions. And after some years I tried to do coding in a "simple" way, that is, using concepts that most languages have, like IF, grouping, loops, etc. - I automatically "learned" to think this way, and so I have to do it this way. And from this point of view I understand Stefan using an environment where he could do it this way, too. (But maybe his reasons were others...)

And while your program is the directest way of coding, I think "normal" coding is the "more direct" way of thinking...

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: AutoHotkey: Dummy File Creator

Post by jacky »

PeterH wrote:jacky, I admire your scripting. 2 lines, and that's it - really great.

But I have "programmed" in maybe 10 "languages" - and now have no interest to learn more, especially reg expressions. And after some years I tried to do coding in a "simple" way, that is, using concepts that most languages have, like IF, grouping, loops, etc. - I automatically "learned" to think this way, and so I have to do it this way. And from this point of view I understand Stefan using an environment where he could do it this way, too. (But maybe his reasons were others...)

And while your program is the directest way of coding, I think "normal" coding is the "more direct" way of thinking...
Well, I'm not saying my script was the best way to do it, and it certainly isn't the only way to do it, and while there are no if...else statements in XYS yet, we already can do conditions (using ternary) and loops quite easily.

I agree that a full support for conditions, loops, etc will be better, but there's already plenty of stuff doable. For instance, you could search for CRLF (strpos) there extract the filename (substr) and create the file (new), all in a loop using a ternary to repeat as long as there's something left in your buffer variable. No need for regexp then. ;)

I was reacting to his "Since i can't do this with XYScripting right now (v7.80)" which sounded (to me) like it wasn't possible, while it absolutely is (and not just using regexp).
Proud XYplorer Fanatic

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: AutoHotkey: Dummy File Creator

Post by Stefan »

jacky wrote:
Stefan wrote:Since i can't do this with XYScripting right now (v7.80) i have dust off an old Autohotkey script for that issue.
Why? Did you even looked at what commands are available,
Yes of course as you know from my last posts :D
like "new" to create new files/folders ?
There's no reason you can't create new files from scripting!
'new' was not the problem, but splitting the string or clipboard content and the loop.
Thank you for showing me an way. :i really need the thumpsup -icon here in this forum:
Here's a very basic script to create files from names in the clipboard:

Code: Select all

  regexreplace $script, <clipboard>, "^(.+?)\r\n", 'new "$1"; ';
  load $script,,s;
Since you search for an string with line break ......and the last string has no \r\n ....... the last file name is not created.
I have tried a few different possibles ..... but always get an additional dot in front or after my file name.
At last this non-100% perfect regex works for me in first tests.

Code: Select all

regexreplace $script, <clipboard>, "^[^.](.+)[^.]$", 'new "$1";' ;load $script,,s;
Where cames those dots from?

.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: AutoHotkey: Dummy File Creator

Post by Stefan »

@Jacky
O.K., so please read it as "Since i can't do this..." :lol:

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: AutoHotkey: Dummy File Creator

Post by jacky »

Stefan: oh yes, I'll put all the blame on you! :P ;)
Stefan wrote:Since you search for an string with line break ......and the last string has no \r\n ....... the last file name is not created.
I have tried a few different possibles ..... but always get an additional dot in front or after my file name.
At last this non-100% perfect regex works for me in first tests.

Code: Select all

regexreplace $script, <clipboard>, "^[^.](.+)[^.]$", 'new "$1";' ;load $script,,s;
Where cames those dots from?
Well, if you don't know regexp a great source of info is this website. (dot means any character)

About your problem, you could test that it ends with a CRLF and if not add one,

Code: Select all

  substr $check, <clipboard>, -2;
  $script = <clipboard> . (($check == <crlf>) ? "" : <crlf>);
  regexreplace $script, $script, "^(.+?)\r\n", 'new "$1"; ';
  load $script,,s;
Proud XYplorer Fanatic

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: AutoHotkey: Dummy File Creator

Post by Stefan »

jacky wrote:...(dot means any character)
I know. I have said (meant) i get an dot as result in front of the file name (or after).
And that isn't clear to me. :roll:
jacky wrote: About your problem, you could test that it ends with a CRLF and if not add one,

Code: Select all

  substr $check, <clipboard>, -2;
  $script = <clipboard> . (($check == <crlf>) ? "" : <crlf>);
  regexreplace $script, $script, "^(.+?)\r\n", 'new "$1"; ';
  load $script,,s;
Yes, that's was i tried the last hour :oops: too.
I'll try to learn :lol: thanks

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: AutoHotkey: Dummy File Creator

Post by Stefan »

OK, i have understood what this script does... and it works as awaited.

And it seams this dots (there are two after each filename in the try-script-preview) i mentioned are the \n and \r signs.
Now all makes sense.

admin
Site Admin
Posts: 66083
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: AutoHotkey: Dummy File Creator

Post by admin »

Stefan wrote:OK, i have understood what this script does... and it works as awaited.

And it seams this dots (there are two after each filename in the try-script-preview) i mentioned are the \n and \r signs.
Now all makes sense.
Ah yes, I do what many HEX viewers do: replace non-printable characters by "." (dot). I'm ready to change this if there's a better idea. Maybe using the pilcrow (¶) especially for 0x13 and 0x10 would be better... :!: :?:

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: AutoHotkey: Dummy File Creator

Post by Stefan »

Where/when do you "replace non-printable characters by "." (dot)" ?
I imagine those chars are needed most times (pasting back as text) and you do replace them sometimes only?
How about to replace them by an space since spaces are ignored while scripting.
Or by nothing. ? :roll:

admin
Site Admin
Posts: 66083
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: AutoHotkey: Dummy File Creator

Post by admin »

Stefan wrote:Where/when do you "replace non-printable characters by "." (dot)" ?
I imagine those chars are needed most times (pasting back as text) and you do replace them sometimes only?
How about to replace them by an space since spaces are ignored while scripting.
Or by nothing. ? :roll:
This is only for display in "Current command (Parsed and resolved)" and in the Variables list. Just a visual feedback. Of course, nothing in the real working script is replaced.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: AutoHotkey: Dummy File Creator

Post by Stefan »

But i not only see this dot(s) --or now this "·" (mid dot)-- ..... my script wants to create an file name including this dot(s)

here an not really functionally script because of this mistake which reproduce this behavior:

Code: Select all

regexreplace $script, <clipboard>, "^(.+)$", 'new "$1";' ;load $script,,s;

that XY wants to use the -to visible chars changed non-printed signs- is not correct IMHO (at least i never saw this behavior elsewhere)
You do not have the required permissions to view the files attached to this post.

admin
Site Admin
Posts: 66083
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: AutoHotkey: Dummy File Creator

Post by admin »

Stefan wrote:But i not only see this dot(s) --or now this "·" (mid dot)-- ..... my script wants to create an file name including this dot(s)
:? Not here. What's on your clipboard in the first place?

Post Reply