incepator Posted October 25, 2012 Share Posted October 25, 2012 How can I delete a specific text in a file? Thank you! expandcollapse popup#include <String.au3> $read = FileOpen("C:\Documents and Settings\UnuRo\Desktop\test\phpfile.php",0) If Not @error Then $string_delete = _StringBetween($citeste,'<!--',"-->") If IsArray($string_delete) Then $write FileOpen("C:\Documents and Settings\UnuRo\Desktop\test\phpfile.php",1) FileWrite($write, ????) EndIf EndIf ;Text Delete in File: #comments-start <!-- /** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE_AFL.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage * @package Mage_Customer * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> #comments-end Link to comment Share on other sites More sharing options...
FireFox Posted October 25, 2012 Share Posted October 25, 2012 (edited) Hi, I think this has already been asked, just use the StringReplace function, or String* functions. Edit : oops, didn't see it was for deleting a licence. Br, FireFox. Edited October 25, 2012 by FireFox Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 25, 2012 Moderators Share Posted October 25, 2012 incepator, Why do you want to remove the licence notice from the file? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
careca Posted October 25, 2012 Share Posted October 25, 2012 Does the file has anything else on it? if not maybe you should consider a file delete - file create method. Just create a new one and write the text u want... Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
guinness Posted October 25, 2012 Share Posted October 25, 2012 Does the file has anything else on it? if not maybe you should consider a file delete - file create method. Just create a new one and write the text u want...I would wait until the OP has answered Melba23's question before offering advice. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
incepator Posted October 25, 2012 Author Share Posted October 25, 2012 (edited) expandcollapse popup#NoTrayIcon #include <File.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Multi File Search Edit", 700, 300, -1, -1) $Button1 = GUICtrlCreateButton("Select Folder Principal", 8, 8, 163, 21, $WS_BORDER) GUICtrlSetCursor(-1, 0) $Input1 = GUICtrlCreateInput("", 176, 8, 489, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_READONLY)) $Label1 = GUICtrlCreateLabel("Insert Extension:", 8, 40, 227, 21, $WS_BORDER) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Input2 = GUICtrlCreateInput("xml", 240, 40, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) $Button2 = GUICtrlCreateButton("Search Text and Del", 320, 40, 171, 25, $WS_BORDER) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) $Edit1 = GUICtrlCreateEdit("", 10, 70, 675, 200) GUICtrlSetData(-1, StringFormat("<!--rn/**rn * Magentorn *rn * NOTICE OF LICENSErn *rn * This source file is subject to the Academic Free License (AFL 3.0)rn * that is bundled with this package in the file LICENSE_AFL.txt.rn * It is also available through the world-wide-web at this URL:rn * http://opensource.org/licenses/afl-3.0.phprn * If you did not receive a copy of the license and are unable torn * obtain it through the world-wide-web, please send an emailrn * to license@magentocommerce.com so we can send you a copy immediately.rn *rn * DISCLAIMERrn *rn * Do not edit or add to this file if you wish to upgrade Magento to newerrn * versions in the future. If you wish to customize Magento for yourrn * needs please refer to http://www.magentocommerce.com for more information.rn *rn * @category Magern * @package Mage_Apirn * @copyright Copyright © 2012 Magento Inc. (http://www.magentocommerce.com)rn * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)rn */rn-->")) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $Folder = FileSelectFolder("Select folder.", @DesktopDir, Default, Default, $Form1) If Not @error Then GUICtrlSetData($Input1, $Folder) EndIf Case $Button2 If GUICtrlRead($Input1) = "" Then MsgBox(64, "Info", "No select folder !") ElseIf GUICtrlRead($Input2) = "" Then MsgBox(64, "Info", "No exist extension !") Else Local $FileList = _FileListToArrayEx(GUICtrlRead($Input1), "*." & GUICtrlRead($Input2), 12) If Not @error Then For $i = 1 To $FileList[0] $citeste = FileOpen($FileList[$i], 0) $read = FileRead($citeste) If Not @error Then $string_delete = StringReplace($read, GUICtrlRead($Edit1), "") FileClose($citeste) $deschide = FileOpen($FileList[$i], 2) If Not @error Then FileWrite($deschide, "") FileWrite($deschide, $string_delete) Sleep(5) FileClose($deschide) EndIf EndIf Next MsgBox(64, "Info", "Finish Edit !") EndIf EndIf EndSwitch WEnd Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0) Local $hSearch, $sFile, $sFileList, $iFlags = StringReplace(BitAND($iFlag, 1) + BitAND($iFlag, 2), "3", "0"), $sSDir = BitAND($iFlag, 4), $FPath = "", $sDelim = "|", $sSDirFTMP = $sFilter $sPath = StringRegExpReplace($sPath, "[/]+z", "") & "" ; ensure single trailing backslash If Not FileExists($sPath) Then Return SetError(1, 1, "") If BitAND($iFlag, 8) Then $FPath = $sPath If StringRegExp($sFilter, "[/:><]|(?s)As*z") Then Return SetError(2, 2, "") If Not ($iFlags = 0 Or $iFlags = 1 Or $iFlags = 2 Or $sSDir = 4 Or $FPath <> "") Then Return SetError(3, 3, "") $hSearch = FileFindFirstFile($sPath & "*") If @error Then Return SetError(4, 4, "") Local $hWSearch = $hSearch, $hWSTMP = $hSearch, $SearchWD, $sSDirF[3] = [0, StringReplace($sSDirFTMP, "*", ""), "(?i)(" & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace("|" & $sSDirFTMP & "|", '|h*|[|h]*', "|"), '[^$()+[]{},.]', "$0"), "|([^*])", "|^$1"), "([^*])|", "$1$|"), '*', ".*"), '^|||$', "") & ")"] While 1 $sFile = FileFindNextFile($hWSearch) If @error Then If $hWSearch = $hSearch Then ExitLoop FileClose($hWSearch) $hWSearch -= 1 $SearchWD = StringLeft($SearchWD, StringInStr(StringTrimRight($SearchWD, 1), "", 1, -1)) ElseIf $sSDir Then $sSDirF[0] = @extended If ($iFlags + $sSDirF[0] <> 2) Then If $sSDirF[1] Then If StringRegExp($sFile, $sSDirF[2]) Then $sFileList &= $sDelim & $FPath & $SearchWD & $sFile Else $sFileList &= $sDelim & $FPath & $SearchWD & $sFile EndIf EndIf If Not $sSDirF[0] Then ContinueLoop $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "*") If $hWSTMP = -1 Then ContinueLoop $hWSearch = $hWSTMP $SearchWD &= $sFile & "" Else If ($iFlags + @extended = 2) Or StringRegExp($sFile, $sSDirF[2]) = 0 Then ContinueLoop $sFileList &= $sDelim & $FPath & $sFile EndIf WEnd FileClose($hSearch) If Not $sFileList Then Return SetError(4, 4, "") Return StringSplit(StringTrimLeft($sFileList, 1), "|") EndFunc How do I search between the 2 parameters? <!-- and --> Thanks Edited October 25, 2012 by incepator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 25, 2012 Moderators Share Posted October 25, 2012 incepator,GUICtrlCreateButton("Search Text and Del"Last chance. Why are you looking to delete a section (or all) of the licence text in that file. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
incepator Posted October 25, 2012 Author Share Posted October 25, 2012 that text is only an example, a simple example ... the text is actually another. Can you help me? thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 25, 2012 Moderators Share Posted October 25, 2012 incepator, I will give you the benefit of the doubt this time - but please choose less controversial examples in future. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
incepator Posted October 25, 2012 Author Share Posted October 25, 2012 I'll be more careful in future, thanks! Link to comment Share on other sites More sharing options...
careca Posted October 25, 2012 Share Posted October 25, 2012 (edited) Hi, you didn't answer my previous question, but anyway, got 2 examples you could try Delete everything in file/replace all with "#comments-start <!-- -->" $File="C:UsersUSERDesktopphpfile.php" $FileContent=FileRead($File,FileGetSize($File)) $Replace=("#comments-start <!-- -->") $FileContent2=StringReplace($FileContent,$FileContent,$Replace) MsgBox(0, "String", $FileContent2) FileDelete($File) FileWrite($File,$FileContent2) this one removes 964 characters from the right/end, and then paste " -->" $File="C:UsersUSERDesktopphpfile.php" $FileContent=FileOpen($File, 0) $FileContent=FileRead($File,FileGetSize($File)) MsgBox(0, "String", $FileContent) $FileContent2=StringTrimRight($FileContent, 964) MsgBox(0, "String", $FileContent) MsgBox(0, "String", $FileContent2) ;FileDelete($File) $File=FileOpen($File, 2) FileWrite($File,$FileContent2&" -->") Im confident there is a String replace pattern that you could use to remove only between what you need, maybe not by itself but what do i know... my knowledge is limited, guinness is the person that can help you much better than me. Edited October 25, 2012 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe 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