Jump to content

Recommended Posts

Posted

Hello y'all,

I use this script to remove @crlf from all lines in a text-file

$czFile = "\test.csv"

;search & replace

$szText = FileRead($szFile,FileGetSize($szFile))

$szText = StringReplace($szText, @CRLF, "")

FileDelete($szFile)

FileWrite($szFile,$szText)

I need to do this with multiple csv-files (which are all located in one folder)

Can someone help me with building the loop that will read te filenames one by one and putting them in this script (as a variable).

?

Posted (edited)

Hi,

#include <file.au3>
; !! there are no error handlings in this code !!
$source = "c:\csv"
;list csv files in $source into array, for more details see helpfile
$arfiles = _FileListToArray ($source, "*.csv", 1)
;loop over array, $arfiles [0] = Number of Files\Folders returned, so we start from 1
For $i = 1 To UBound ($arfiles) - 1
    ;search & replace
    $szFile = $source & "\" & $arfiles [$i]
    $szText = FileRead($szFile,FileGetSize($szFile))
    $szText = StringReplace($szText, @CRLF, "")
    FileDelete($szFile)
    FileWrite($szFile,$szText)
Next

;-))

Stefan

Edited by 99ojo

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
×
×
  • Create New...