Jump to content
Sign in to follow this  
pbecks1963

edit multiple files (remove @crlf)

Recommended Posts

pbecks1963

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

?

Share this post


Link to post
Share on other sites
99ojo

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

Share this post


Link to post
Share on other sites
pbecks1963

thnx!

Share this post


Link to post
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
Sign in to follow this  

×