Jump to content

Recommended Posts

Posted

Func _RemoveLeadingCharsFromFile($sInFile, $sOutFile, $iRemoveChars)

Local $sAll, $hFile

$sAll = FileRead($sInFile, FileGetSize($sInFile))

$hFile = Fileopen($sOutFile, 2)

FileWrite($hFile, stringmid($sAll, $iRemoveChars + 1,filegetsize($sInFile)))

FileClose($hFile)

EndFunc

remember i am new at this :lmao:

Posted

  chewy said:

Func _RemoveLeadingCharsFromFile($sInFile, $sOutFile, $iRemoveChars)

    Local $sAll, $hFile

    $sAll = FileRead($sInFile, FileGetSize($sInFile))

    $hFile = Fileopen($sOutFile, 2)

    FileWrite($hFile, stringmid($sAll, $iRemoveChars + 1,filegetsize($sInFile)))

    FileClose($hFile)

EndFunc

remember i am new at this :lmao:

<{POST_SNAPBACK}>

New's okay! Good try, had me going for a few seconds. The problem is that when the output file is opened, it is necessarily opened in write mode, which means it erases every thing in the existing file. As such, FileGetSize returns zero when used at the point you are using it.

If you want to specify the count, or you are not using the latest version of AutoIt, here's the revised function:

Func _RemoveLeadingCharsFromFile($sInFile, $sOutFile, $iRemoveChars)
   Local $sAll, $hFile, $iSize
   $iSize = FileGetSize($sInFile)
   $sAll = FileRead($sInFile, $iSize)
   $hFile = Fileopen($sOutFile, 2)
   FileWrite($hFile, stringmid($sAll, $iRemoveChars + 1, $iSize))
   FileClose($hFile)
EndFunc

Phillip

  • 6 months later...
Posted

another question about this. Now I also need to erase the last character in the file.

This is what I use to delete the first 2 characters and it work perfect

  Quote

Func _RemoveLeadingCharsFromFile($sInFile, $sOutFile, $iRemoveChars)

    Local $sAll, $hFile

    $sAll = FileRead($sInFile, FileGetSize($sInFile))

    $hFile = Fileopen($sOutFile, 2)

    FileWrite($hFile, stringmid($sAll, $iRemoveChars + 1,filegetsize($sInFile)))

    FileClose($hFile)

EndFunc

now I need to delete out the last character in the file.

Any ideas?

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
  • Recently Browsing   0 members

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