0
一些大型網站的網上有不正確的文檔類型(4.0不是4.01)。我已經寫了一個腳本來更新這個內容的任何文件,但它更新了文件的修改日期,並且我想保留它作爲原始日期,這是可能的vbscript(與經典的asp)?如何使用vbscript更新文件內容而不更新它的修改日期?
這裏是我的代碼只需替換該文件的內容:
' My folder root is here
FileRoot = "D:\myRootHere\"
' Now I use Persits upload because I need the impersonation setting below it
Set Upload = Server.CreateObject("Persits.Upload")
' Set impersonation to authorise file over-writing (this is correct and working)
Upload.LogonUser "localhost","myUsername","myPassword"
Set Dir = Upload.Directory(FileRoot & "*.asp", SORTBY_TYPE)
For Each item in Dir
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileRoot & item.FileName, ForReading)
strText = objFile.ReadAll
objFile.Close
If instr(strText,"HTML 4.0 Transitional") then
strNewText = Replace(strText,"HTML 4.0 Transitional","HTML 4.01 Transitional")
Set objFile = objFSO.OpenTextFile(FileRoot & item.FileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close
End If
Next
Set Upload = nothing
想要在文件系統不知道的情況下更新文件嗎?我是_guessing_這是不可能的(無論如何,沒有一些真正的低級代碼,直接修改文件系統數據),或者至少不是一個好主意。出於好奇,_why_你不想讓文件系統知道文件已被修改嗎?這聽起來像問題的根源在設計的其他地方。 – David 2013-05-08 15:57:20
嗨大衛 - 我喜歡看到mod日期作爲一個提醒,我已經對之前的代碼進行了重大更改,並將它們與我的離線副本相匹配,作爲一些其他開發人員也在網站上工作,並且我想確保所有內容都處於同步狀態。我想知道是否可以讀取mod日期,然後在寫入文件時寫入mod日期? – tobzzz 2013-05-08 16:13:12
這聽起來像文件修改日期不是你應該使用的。它不會跟蹤文件的「重大」更改,它會跟蹤文件的任何*更改。您的源代碼管理系統應該內部跟蹤這些更改的實際內容(以及製作它們的人員,製作時間等)。 – David 2013-05-08 16:17:39