Read File
FileNo = Freefile ' Establish free file handle
Open pathfile For Input As FileNo
Do While Not EOF(FileNo)
Line Input #FileNo, CurrentLine
Loop
Close #FileNo
Write files
FileWr = Freefile ' Establish free file handle
Open pathDest For Output As #FileWr
Print #FileWr, fileContent
Close #FileWr
other version for writing
Set fs = CreateObject("Scripting.FileSystemObject")
'True overwrite, False not overwrite
Set a = fs.CreateTextFile("c:\test.txt", True)
a.WriteLine("Questa è una prova.")
a.Close
other version for reading
Dim fso, f1, ts, s
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set ts = fso.OpenTextFile("c:\fileprova.txt", ForReading)
Do
s = ts.ReadLine
Loop Until ts.AtEndOfStream = True
'Check if the folder exists
If Not fs.FolderExists("C:\FolderName") Then
'Create folder
fs.CreateFolder "C:\FolderName"
End if
Lettura del numero di caratteri specificato Read
Lettura di un'intera riga fino al carattere di nuova riga escluso ReadLine
Sub test55()
strComputer = "."
strFolder = "R:\sys\XMLData"
strNewFolder = "C:\tmp"
strDateFrom = "20140307000000.000000+00" ' 06/11/2009
strDateTo = "20140308000000.000000+00" ' 06/12/2010
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colFiles = oWMI.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strFolder & "'} WHERE " _
& "ResultClass = CIM_DataFile")
For Each oFile In colFiles
If oFile.CreationDate > strDateFrom And oFile.CreationDate < strDateTo Then
Debug.Print "Full path: " & oFile.Name
Debug.Print "Creation date: " & oFile.CreationDate
oFile.Copy strNewFolder & "\" & oFile.Filename & "." & oFile.Extension
'oFile.Delete
End If
Next
End Sub
Sub test66()
strComputer = "."
strDateFrom = "20140307000000.000000+00" ' 06/11/2009
strDateTo = "20140308000000.000000+00" ' 06/12/2010
strNewFolder = "C:\tmp"
strFolder = "\\sys\\XMLData"
iFlags = 48
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
qry = "SELECT * FROM CIM_DataFile" & _
" WHERE Drive = 'R:' AND Path = '" & strFolder & "\\'" & _
" AND LastModified >= '" & strDateFrom & "'" & _
" AND LastModified <= '" & strDateTo & "'"
Set colFiles = oWMI.ExecQuery(qry, , iFlags)
'" AND CreationDate >= '" & strDateFrom & "'" & _
'" WHERE Drive = 'R:' AND Path = '\\" & strFolder & "\\'" & _
Dim a
For Each oFile In colFiles
'a = oFile.FileInfo
Debug.Print "Full path: " & oFile.Name
Debug.Print "Creation date: " & oFile.LastModified
oFile.Copy strNewFolder & "\" & oFile.Filename & "." & oFile.Extension
'oFile.Delete
Next
End Sub