Ok i’ve converted the code into a method (i’m now using it for another robocopy log cleanup job too) and switched to a do loop. For sake of completion i’m posting the method Everything works and i’ve managed to execute within reasonable times both jobs.
I’ve created a filetypes file describing a txt and csv save option (its just a formal thing, the content is the same) and the method has two parameters: Type(defining if i’m checking a certain type of export or another one, the only change is the csv header string and the chars to remove from the path count) and separator(to create csv with semicolon or comma separated data).
[code] 'Define variables+objects
Dim f As FolderItem
Dim tis As TextInputStream
Dim s As string
Dim fields() As string
Dim inputrow As string
Dim outputrow As string
Dim CSVf As FolderItem
Dim fileStream As TextOutputStream
Dim chars As Int32
Dim diskletter As string
Dim year As string
Dim diskstring As string
Dim datestring As string
Dim CSVsep As string
Dim CSVheader As string
Dim headermode As Integer
Dim filename As string
Dim diskid As string
Dim yearid As string
'Initialize variables
diskletter =“d”
diskid = diskletter + “:”
year =“2014”
yearid = year + “/”
headermode = 1
'Method setup
If Separator = 0 then
CSVsep = “;”
elseif Separator = 1 then
CSVsep = “,”
end if
If Type = “newfiles” then
chars = 28
CSVheader = “Size” + CSVsep + “Date” + CSVsep + “Path” + CSVsep + “Pathlength”
filename = “newexport.txt”
elseif Type = “longpaths” then
chars = 21
CSVheader = “Date” + CSVsep + “Path” + CSVsep + “Pathlength”
filename = “longexport.txt”
else
MsgBox(“Wrong type, please contact the developer to verify action source code”)
End if
datestring = CSVsep + yearid 'prepare date separator object
diskstring = CSVsep + diskid 'prepare disk letter separator object
'Select output file/folder
CSVf = GetSaveFolderItem(FileTypes1.ALL,filename)
If CSVf <> Nil Then
MsgBox(“Save path is”+ Endofline+CSVf.Nativepath)
End If
'Select input file
f = GetOpenFolderItem(“any” )
if f=nil then exit sub 'cancel clicked
'open the file
tis = f.OpenAsTextFile
if tis=nil then 'failed?
MsgBox(“The file could not be opened.”)
exit sub
end if
'compile new file
do
s=tis.ReadLine 'read line from file
if s <> “” then
s = trim(s) 'remove trailing spaces
inputrow = replace (s, diskid, diskstring) 'use the disk letter to add the first column separator
If type =“newfiles” then
inputrow = replace (inputrow, yearid, datestring) 'use the year to add the second column separator on newfiles mode
end if
outputrow=(inputrow + CSVse" + format(len(inputrow) - chars,“0”)) 'execute the path char count routine and remove the corresponding number of chars from the total
'create output filestream if CSV is empty else append to existing file
if Headermode = 1 then
fileStream = TextOutputStream.Create(CSVf) 'create file
fileStream.WriteLine(CSVHeader) 'write header
Headermode = 0 'revert to standard mode
else
fileStream = TextOutputStream.Append(CSVf) 'append data to file
end if
fileStream.WriteLine(outputrow) 'input currentline
fileStream.Close 'close filestream
end if
loop until tis.eof
tis.Close 'close file[/code]
Again, thank you all for the all useful hints and suggestions