I want to convert all files to dos to unix format from a folder using VBA excel.
i can find all the files from drive by using following code.
Sub list_all_files(myFilepath As String, filecounter() As Variant, counter1 As Integer)
With Application.FileSearch
.NewSearch
.LookIn = myFilepath
.filename = "*.*"
counter = 0
If .Execute(SortBy:=msoSortByLastModified, SortOrder:=msoSortOrderDescending) > 0 Then
counter1 = .FoundFiles.Count
For i1 = 1 To .FoundFiles.Count
counter = counter + 1
filecounter(counter) = .FoundFiles(i1)
Next i1
End If
End With
End Sub
But How to convert arrayof(files). I want to save the files on the same path.
Thanks in advance.
You would have to open each file in turn and run a find-and-replace operation on the input:
vbCrLf(DOS) goes tovbLf(Unix). You’d then have to write that updated file back out to another file… Alternatively, rather than doing this sequentially, you could scan through each file, writing it back to another at the same time but ignoring all the carriage returns.A quick Google found example code (e.g., here) to do the trick.