Wolvereness Posted January 22, 2005 Share Posted January 22, 2005 (edited) Wow, I was working on this without going to do it manually and have it do a floating return-value type. It will do any file in less then a second. There are 2 funcs, the first one will take the given file and copy with a new extension. The second is the Adapt(). Syntax is (Nickname, FilePath). When called when uncompiled it will take given file and write it into the script with new extension .new.au3. After calling it mutliple times in same script it will just add it to the list. When calling it while compiled it will re-install the file.Advantage of using this function other then FileInstall(), when decompiled it will have the file withen the decompiled script.Func _FileChangeExt($s_FilePath = '', $s_Extension) If StringLeft($s_Extension, 1) = '.' Then Local $s_Extension = StringTrimLeft($s_Extension, 1) If Not FileExists($s_FilePath) Or $s_Extension = '' Then Return 0 StringReplace($s_FilePath, '\', 'nothing') Local $i_FolderLevel = @extended StringReplace($s_FilePath, '.', 'nothing') Local $i_DotLevel = @extended If Not $i_DotLevel Or Not $i_FolderLevel Then Return 0 Local $s_TemporaryPath = @TempDir & '/' & StringRight($s_FilePath, StringLen($s_FilePath) - StringInStr($s_FilePath, '\', 0, $i_FolderLevel)) FileCopy($s_FilePath,$s_TemporaryPath) FileMove($s_TemporaryPath, StringLeft($s_FilePath, StringInStr($s_FilePath, '.', 0, $i_DotLevel)) & $s_Extension) Return 1 EndFunc Func _Adapt($s_NickName, $s_File = '') If Not @Compiled Then StringReplace($s_File,'.','') Local $s_Ext = StringTrimLeft($s_File, StringInStr($s_File, '.', 0, @extended) - 1) Local $h_File = FileOpen(StringTrimRight(@ScriptName, 4) & '.' & $s_NickName & '.au3w', 2) FileWrite($h_File, '#Include-Once' & @CRLF & 'Func _Adapt' & StringReplace($s_NickName, ' ', '') & '()' & @CRLF & "Return FileWrite(@ScriptDir & '\" & $s_NickName & $s_Ext & "','" & StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(FileRead($s_File, FileGetSize($s_File)),@CR, @LF),@LF & @LF, @LF), @LF, "' & @CRLF & ' _" & @CRLF), '"', '""'), "')", "''") & "')" & @CRLF & 'EndFunc') _FileChangeExt(@ScriptFullPath, 'New.au3') FileClose($h_File) FileWrite(StringTrimRight(@ScriptName, 4) & '.New.au3', @CRLF & '#include "' & StringTrimRight(@ScriptName, 4) & '.' & $s_NickName & '.au3w"') Else Return Call('_Adapt' & StringReplace($s_NickName, ' ', '')) EndIf EndFuncPlease post any bugs/suggestions/fixes/Edit, Inspired by http://www.autoitscript.com/forum/index.php?showtopic=7773 Edited January 22, 2005 by Wolvereness Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote] Link to comment Share on other sites More sharing options...
Sigi2 Posted January 24, 2005 Share Posted January 24, 2005 (edited) nice idea - but can you give an example to understand the function? this is the error i get ... C:\test\test.au3 (4) : ==> Badly formatted "Func" statement.: Func _FileChangeExt($s_FilePath = '', $s_Extension) thx, sigi Edited January 24, 2005 by Sigi2 Link to comment Share on other sites More sharing options...
SlimShady Posted January 24, 2005 Share Posted January 24, 2005 You need the latest beta.Available here:http://www.autoitscript.com/autoit3/files/beta/autoit/ Link to comment Share on other sites More sharing options...
Valik Posted January 24, 2005 Share Posted January 24, 2005 nice idea - but can you give an example to understand the function? this is the error i get ...C:\test\test.au3 (4) : ==> Badly formatted "Func" statement.: Func _FileChangeExt($s_FilePath = '', $s_Extension)thx,sigi<{POST_SNAPBACK}>All parameters after an optional parameter must also be optional. Either the order of parameters to that function need swapped or $s_Extension needs to be assigned a default value. Link to comment Share on other sites More sharing options...
Wolvereness Posted January 24, 2005 Author Share Posted January 24, 2005 (edited) Sigi, update your version of this func. I had that debugged. Also, thanks for the comment. Edited January 24, 2005 by Wolvereness Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote] 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