流放之路脚本办公

笔者通过与网友共同探讨和尝试,发现它可以以字符串的形式获得包含路径在内的完整的FileName,这无疑是很有用的Dim n, ws, fsoX, thePath Set ws=CreateObject("WScript.Shell") Set fsoX=CreateObject("Scripting.FileSystemObject") thePath=ws.Exec("cmd /c cd").StdOut.ReadAll() & "" i=InStr(thePath, Chr(13)) thePath=Left(thePath, i - 1) n=len(thePath) On Error Resume Next addToMdb(thePath) Wscript.Echo "当前目录已经打包完毕,根目录为当前目录" Sub addToMdb(thePath) Dim rs, conn, stream, connStr Set rs=CreateObject("ADODB.RecordSet") Set stream=CreateObject("ADODB.Stream") Set conn=CreateObject("ADODB.Connection") Set adoCatalog=CreateObject("ADOX.Catalog") connStr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Packet.mdb" adoCatalog.Create connStr conn.Open connStr conn.Execute("Create Table FileData(Id int IDENTITY(0,1) PRIMARY KEY CLUSTERED, thePath VarChar, fileContent Image)") stream.Open stream.Type=1 rs.Open "FileData", conn, 3, 3 fsoTreeForMdb thePath, rs, stream rs.Close Conn.Close stream.Close Set rs=Nothing Set conn=Nothing Set stream=Nothing Set adoCatalog=Nothing End Sub Function fsoTreeForMdb(thePath, rs, stream) Dim i, item, theFolder, folders, files sysFileList="$" & WScript.ScriptName & "$Packet.mdb$Packet.ldb$" Set theFolder=fsoX.GetFolder(thePath) Set files=theFolder.Files Set folders=theFolder.SubFolders For Each item In folders fsoTreeForMdb item.Path, rs, stream Next For Each item In files If InStr(LCase(sysFileList), "$" & LCase(item.Name) & "$") <=0 Then rs.AddNew rs("thePath")=Mid(item.Path, n + 2) stream.LoadFromFile(item.Path) rs("fileContent")=stream.Read() rs.Update End If Next Set files=Nothing Set folders=Nothing Set theFolder=Nothing End Function

易语言手机脚本 看起来是否很麻烦?然而,使用以下的函数就能解决这个问题

'This code is done by KangKang@ Option explicit ‘This is optional, but better to use. Dim FolderPath,Folder Dim fso,File,Files Dim fileNums Dim FileString() Dim i Dim ii i=0 FolderPath="E:\TDDOWNLOAD\aa" '**********************1.To create the FileSystemObject object******************************** Set fso=CreateObject("Scripting.FileSystemObject")'This is the way to create FileSystemObjecy ‘这句话在Excel VBA中也可以如此定义来引用FSO! 'Scripting是类库的名字,filesystemobject是所引用的对 '象, 说明了此时VBA所用的对象不是自带的,而是引用 '外界的PrivateDeclareFunctionCreateDirectoryLib"kernel32"Alias"CreateDirectoryA"(ByVallpPathNameAsString,lpSecurityAttributesAsSECURITY_ATTRIBUTES)AsLongPrivateTypeSECURITY_ATTRIBUTESnLengthAsLonglpSecurityDescriptorAsLongbInheritHandleAsLongEndTypeSubMain()'在C盘创建了"VB编程乐园"目录CallCreateNewDirectory("C:\VB编程乐园")MsgBox"在C盘创建了VB编程乐园目录"EndSubPublicSubCreateNewDirectory(NewDirectoryAsString)DimsDirTestAsStringDimSecAttribAsSECURITY_ATTRIBUTESDimbSuccessAsBooleanDimsPathAsStringDimiCounterAsIntegerDimsTempDirAsStringDimiFlagAsIntegeriFlag=0sPath=NewDirectoryIfRight(sPath,Len(sPath))<>""ThensPath=sPath&""EndIfiCounter=1DoUntilInStr(iCounter,sPath,"")=0iCounter=InStr(iCounter,sPath,"")sTempDir=Left(sPath,iCounter)sDirTest=Dir(sTempDir)iCounter=iCounter 1'创建目录SecAttrib.lpSecurityDescriptor=&O0SecAttrib.bInheritHandle=FalseSecAttrib.nLength=Len(SecAttrib)bSuccess=CreateDirectory(sTempDir,SecAttrib)LoopEndSub->

DOS批处理不再黑屏的vbs脚本 DIMobjShell n]h/K,cQ'xe0setōbjShell=wscrīpt.createObject("wscrīpt.shell")linux博客?w

28人参与, 0条评论 登录后显示评论回复

你需要登录后才能评论 登录/ 注册