How to manage windows files via Scripting.FileSystemObject? | Minicoder

Intruduction

If you are an operation and maintainence engineer, you should have mountains of of work to manage windows files including backup ,migration , statstics etc. This article are trying to explain most common interfaces to interact with windows file system.

'Description:
'    Function to create file with specific file name
'Input: 
'    fullPathStr: the absolute path of the file
'    fullFileNameStr: the full name of the file including the file extension
'Output:
'    none
'Throw Exception When:
'    none

public function create_Log_File(fullPathStr, fullFileNameStr)
    on error resume next
        if right(fullPathStr) <> "\" and right(fullPathStr) <> "/" then
            fullPath = fullPathStr & "\" & fullFileNameStr     
        else
            fullPath = fullPathStr & fullFileNameStr
        end if

        set fsObj = CreateObject("Scripting.FileSystemObject")
        if fsObj.FolderExist(fullPathStr) then
            if fsObj.FileExist(fullFileNameStr) then
                fsObj.DeleteFile(fullPath)
            else
                fsObj.OpenTextFile(fullPath, 2, true)
            end if
        else
            Err.Raise 10000, "create_Log_File" , "Folder not exist"
        end if
    on error goto 0
end function   

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章