Jump to content

_FileCreate .bat


Recommended Posts

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

Link to comment
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().

: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
Link to comment
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)

Link to comment
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:

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...