pokwuk Posted May 12, 2011 Share Posted May 12, 2011 Hi , I managed to get the _filecreating working , but it doesnt create as .bat I wanted the script to create a .bat with the contents of the Clip $text = WinGetText("[CLASS:Notepad]", "") $textFile = "C:\03.bat" If Not FileExists($textFile) Then $file = _FileCreate(Random(1,999,0)) FileWrite($file, $text) FileClose(FileOpen($textFile, 1)) EndIf Sleep(300) $nameToReplace = _StringBetween($text , "example1", "example2") _FileWriteToLine( $textFile, 1, StringReplace($text, $nameToReplace[0] , ClipGet()),1) So the script knows the 03.bat its not there , so it will create a new one with a random name and "paste" from the clip what he copied from another file, now its saving a file with a random name but not as .bat. Could you help me adding the .bat somewhere , i've tried as it says on the help file but it doesnt seem to save with random name. Thanks Link to comment Share on other sites More sharing options...
wakillon Posted May 12, 2011 Share Posted May 12, 2011 (edited) Try : $file = _FileCreate ( @TempDir & '\' & Random ( 1, 999, 1 ) & '.bat' ) Edited May 12, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 12, 2011 Share Posted May 12, 2011 (edited) First, _FileCreate() creates exactly the file name you give it. If you want ".bat" on the end, then specify that in _FileCreate(). Next, _FileCreate() does not return an open file handle the way FileOpen() does, so $file is only 1 or 0 based on the returned success of _FileCreate(). Edited May 12, 2011 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jchd Posted May 12, 2011 Share Posted May 12, 2011 _TempFile is also quite flexible This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
pokwuk Posted May 12, 2011 Author Share Posted May 12, 2011 First, _FileCreate() creates exactly the file name you give it. If you want ".bat" on the end, then specify that in _FileCreate(). Next, _FileCreate() does not return an open file handle the way FileOpen() does, so $file is only 1 or 0 based on the returned success of _FileCreate(). Thanks for you reply , the .bat is now being created , but somehow its not "pasting" the content from the clip on the file created. what if we do other way around ? $text = WinGetText("[CLASS:Notepad]", "") $textFile = "C:\03.bat" If FileExists($textFile) Then $file = _FileCreate ( @ScriptDir & '\' & Random ( 1, 999, 1 ) & '.bat' ) FileWrite($textfile, $text) EndIf Sleep(300) $nameToReplace = _StringBetween($text , "example1", "example2") _FileWriteToLine( $file, 1, StringReplace($text, $nameToReplace[0] , ClipGet()),1) So , now its retrieving information from 03 , and pasting into the new random file name , is that possible ? Am i missing something ? thanks in advance Link to comment Share on other sites More sharing options...
pieeater Posted May 12, 2011 Share Posted May 12, 2011 try using clipget() as a variable: $var = ClipGet() just fyi, i don't usually use Clip__() fucntions:/ so i'm probably wrong, but don't you need ClipPut()? [spoiler]My UDFs: Login UDF[/spoiler] Link to comment Share on other sites More sharing options...
wakillon Posted May 13, 2011 Share Posted May 13, 2011 Thanks for you reply , the .bat is now being created , but somehow its not "pasting" the content from the clip on the file created. what if we do other way around ? $text = WinGetText("[CLASS:Notepad]", "") $textFile = "C:\03.bat" If FileExists($textFile) Then $file = _FileCreate ( @ScriptDir & '\' & Random ( 1, 999, 1 ) & '.bat' ) FileWrite($textfile, $text) EndIf Sleep(300) $nameToReplace = _StringBetween($text , "example1", "example2") _FileWriteToLine( $file, 1, StringReplace($text, $nameToReplace[0] , ClipGet()),1) So , now its retrieving information from 03 , and pasting into the new random file name , is that possible ? Am i missing something ? thanks in advance _FileWriteToLine has 4 parameters and you try with 5, so... no need to paste in file, just write it ! $text = WinGetText("[CLASS:Notepad]", "") $textFile = "C:\03.bat" If FileExists($textFile) Then $file = @ScriptDir & '\' & Random ( 1, 999, 1 ) & '.bat' _FileCreate ( $file ) FileWrite($textfile, $text) EndIf Sleep(300) $nameToReplace = _StringBetween($text , "example1", "example2") _FileWriteToLine( $file, 1, StringReplace($text, $nameToReplace[0], 1 ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now