公司给个任务,在某个路径下,所有.abc为后缀文件名为ACCESS数据库的文件,默认有一行hello的用户的记录,密码是123123123,批量把这行记录拿掉。
记录一下,以后省得再弄,不太懂vb弄了个灰头土脸,再回头看看以前那公司的所谓的维护网管,真不懂他们能“维护”什么东西,无论是windows还是linux在我看来。
Dim objFSO Dim ofolder Dim objStream Dim strSearch Dim strfolderSearch Set objFSO = CreateObject("scripting.filesystemobject") Set objStream = objFSO.createtextfile("c:\resolved.txt", True) strfolderSearch = "E:\wwwroot" strSearch = ".abc" strLen=Len(strSearch) CheckFolder (objFSO.getfolder(strfolderSearch)), objStream MsgBox "File Search Completed." + vbCr + "Please check c:\resolved.txt for details." Sub CheckFolder(objCurrentFolder, objtxtFile) On Error Resume Next Dim strTemp Dim strOutput Dim objNewFolder Dim objFile Dim objStream For Each objFile In objCurrentFolder.Files strTemp = Right(objFile.Name, strLen) If UCase(strTemp) = UCase(strSearch) Then objtxtFile.writeline CStr(objFile.Path) Dim Conn,SQL Dim dbPath,Password Set conn = CreateObject("ADODB.Connection") dbPath=objFile.Path Password="123123123" Conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&dbPath&";User ID="¶m_dbUserID&";Password="&Password If Err Then objtxtFile.writeline CStr(objFile.Path) + "-----------" + err.tostring + "----------Failed !" Err.CLEAR Set Conn = NOTHING Else Set RS = Conn.Execute("Select * From admin Where name='hello'") If RS.recordcount > 0 Then Conn.Execute("Delete From admin Where name='hello'") End If Conn.close End if End If Next For Each objNewFolder In objCurrentFolder.subFolders CheckFolder objNewFolder, objtxtFile Next End Sub
虽然看起来有点模糊不过还是能了解一点!
呵呵,这个我懂,遍历目录下所有文件,保存文件列表,然后连接文件列别下的access数据库,然后就是执行SQL了,先判断有没有,有的话删除。OK
网上应该有这样的修改软件
兄弟的沙发我非常乐意坐!
问题是,你的文章太专业了,我们都是外行人,看不懂,看来只有看热闹了。
期待看到一些非专业性的 POSTS 问世。。。