Hi All. A question regarding the automation control Microsoft Scripting Runtime - FSO. I have been able to select a directory, return the number of files in the directory of folder, but what I can’t do is go through each file and rename it (copy and delete)! [:(!] I am using Navision Attain GB 3.60 - SQL 2000 back end (not that it matters). So can anyone help please? [:(]
Why don’t you just use a variable of the type “Record” and subtype “File” ? small example:
File.SETRANGE(Path,'C:\'); IF File.FIND('-') THEN REPEAT MESSAGE('%1 %2 %3 %4', File.Name, File.Date, File.Time, File.Size); File.CALCFIELDS(Data); File.Data.CREATEINSTREAM(InStrm); // perform some read transactions of the file here if you want UNTIL File.NEXT = 0;
Thanks for your response Thomas However, I need to use the fso [:(]
Why don’t you just use a variable of the type “Record” and subtype “File” ?
One of the problems with the File virtual table is that the Path field is Code98. This may have been OK back in the good old days of DOS. But with the longer folder names available today it is not too difficult to have a path that exceeds the 98 character maximum for this field and the File table can’t handle it. I would be very interested if there was a way to use FSO for this type of processing.
When C/AL can’t do it, try a little VBScript (or jScript, for that matter…): ‘objVBScript’ is Automation, ‘Microsoft Script Control 1.0’.ScriptControl;
CREATE(objFSO); objFolder := objFSO.GetFolder('c:\temp'); objFiles := objFolder.Files; CREATE(objVBScript); objVBScript.Language := 'VBScript'; objVBScript.AddCode('Option Explicit'); objVBScript.AddObject('oFiles', objFiles); objVBScript.AddCode( 'Dim fNames(): ' + 'Sub SplitFiles(): ' + ' ReDim fNames(oFiles.Count - 1): ' + ' Dim i: ' + ' i = 0: ' + ' For Each oFile in oFiles: ' + ' fNames(i) = oFile.Name: ' + ' i = i + 1: ' + ' Next: ' + 'End Sub:' + 'Function GetFileName(i): ' + ' GetFileName = fNames(i - 1): ' + 'End Function'); objVBScript.ExecuteStatement('Call SplitFiles'); FOR i := 1 TO objFiles.Count DO BEGIN txtFileName := objVBScript.Eval(STRSUBSTNO('GetFileName(%1)',i)); objFile := objFiles.Item(txtFileName); MESSAGE('File Name: %1\\File Size: %2', objFile.Name,objFile.Size); END; objVBScript.Reset; CLEAR(objVBScript); CLEAR(objFile); CLEAR(objFiles); CLEAR(objFSO);