Jump to content

filewrite ...delete text in a file


Recommended Posts

How can I delete a specific text in a file?

Thank you!

#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

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 by FireFox
Link to comment
Share on other sites

  • Moderators

incepator,

Why do you want to remove the licence notice from the file? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

#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 by incepator
Link to comment
Share on other sites

  • Moderators

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. :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

incepator,

I will give you the benefit of the doubt this time - but please choose less controversial examples in future. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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...