Jump to content

filewrite all files in folders/subfolders


bluerein
 Share

Recommended Posts

I have around 4000 txt files in a directory with subdirectorys .. I need to remove the last line of each file and replace with a new line....

Whats the best way to go about it??

Thanks

_FileListToArray, and then run through the array with a For...Next loop. For each file in the loop, you'd have to count the lines in the file and then do a _FileWriteToLine to delete the last line. In summation, read the help file topics for _FileListToArray, For...Next, _FileCountLines and _FileWriteToLine.

Edited by Airwolf
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

Or use FileFindFirstFile/FileFindNextFile to step through the directory structure recursively.

$sPath = "C:\my\Txt\Directory"
RecurseDirs($sPath, "txt")

Func RecurseDirs ($sPath, $sExt, $sSpacer = " ")
    Local $hSearch, $sFile, $sFilePath
    $hSearch = FileFindFirstFile($sPath & "\*")
    If $hSearch = -1 Then Return
    
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        
        $sFilePath = $sPath & "\" & $sFile
        If StringInStr(FileGetAttrib($sFilePath), "D") <> 0 Then
            ConsoleWrite($sSpacer & $sFilePath & @LF)
            RecurseDirs($sFilePath, $sExt, $sSpacer & "  ")
        Else
            If StringRegExp($sFile, "(?i)\." & $sExt & "\z", 0) Then
                ; Add File Read/Write processing here
                ConsoleWrite($sSpacer & $sFilePath & @LF)
            EndIf
        EndIf
    WEnd
EndFunc
Edited by zorphnog
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...