Sign in to follow this  
Followers 0
pokwuk

_FileCreate .bat

7 posts in this topic

Hi ,

I managed to get the _filecreating working , but it doesnt create as .bat :unsure:

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try :

$file = _FileCreate ( @TempDir & '\' & Random ( 1, 999, 1 ) & '.bat' )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#3 ·  Posted (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().

:unsure:

Edited 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

Share this post


Link to post
Share on other sites

_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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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 :unsure:

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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 :unsure:

_FileWriteToLine has 4 parameters and you try with 5, so...Posted Image

no need to paste in file, just write it ! Posted Image

$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.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0