eyeball Posted February 27, 2006 Share Posted February 27, 2006 hello,i can export the contents of a drive with batch scripting using > dir /B for bare heading format but i have a lot of drives and have to create a seperate script for each drive so my question is this..how can i make a .vbs script (or other) to check for a drive and if it exists export its contents to a text file in bare format?thank you for your time Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 28, 2006 Share Posted February 28, 2006 Here a vbs script that list all the files and folder on a drive, this leaves a text file where it was ran from.I will add a loop to it later to go threw all local hardd drives later if you want.Dim Act, CD, CName, colFiles, Ct1, Ct2,FileRpt, Fso, fVar1, fVar2, GB, Ln1, MB, objF, Ts, UName Dim Subfolder , SubFDC, SubFDLA, SubFDrv, SubFDLM, SubFName, SubFPath, SubFType, ZCD Dim Time1, Time2, Time3 Time1 = Timer() Set Fso = CreateObject("Scripting.FileSystemObject") Set Act = CreateObject("Wscript.Shell") CD = Act.CurrentDirectory ZCD = CD : ZCD = Split(ZCD,":") CName = Act.ExpandEnvironmentStrings("%ComputerName%") UName = Act.ExpandEnvironmentStrings("%UserName%") Ln1 = Space(2) & Chr(171) & " ----------- " & Chr(187) & Space(2) MB = 1024 * 1024 : GB = MB * MB FileRpt = (ZCD(0) & "_" & UName & "_DirList.Txt") Ct1 = 0 : Ct2 = 0 Set Ts = Fso.CreateTextFile(FileRpt) Ts.WriteLine Now() & Ln1 & UName & Ln1 ' Ts.WriteBlankLines(2) '''' START THE SEARCH THREW THE PARENT FOLDER AND SUB FOLDER ShowSubfolders Fso.GetFolder(CD) FinishScript Function ShowSubFolders(Folder) On Error Resume Next For Each Subfolder in Folder.SubFolders Ct1 = Ct1 + 1 SubFDrv = "Folder Drive : " & Subfolder.Drive SubFPath = "Folder Path : " & Subfolder.Path SubFName = "Folder Name : " & Subfolder.Name SubFDC = "Folder Date Created : " & Subfolder.DateCreated SubFDLA = "Folder Date Accessed : " & Subfolder.DateLastAccessed SubFDLM = "Folder Date Modified : " & Subfolder.DateLastModified SubFType = "Folder Type : " & Subfolder.Type Set colFiles = Subfolder.Files MakeReport ShowSubFolders Subfolder Next Exit Function End Function '''' Function MakeReport Set colFiles = Subfolder.Files For Each objF in colFiles Ct2 = Ct2 + 1 fVar1 = objF.Size ConvertFileSize Ts.WriteLine SubFDrv & vbCrLf & SubFPath & vbCrLf & SubFName & vbCrLf & SubFDC Ts.WriteLine SubFDLA & vbCrLf & SubFDLM & vbCrLf & SubFType Ts.WriteLine "File Path : " & objF.Path Ts.WriteLine "File Name : " & objF.Name Ts.WriteLine fVar1 Ts.WriteLine "File Date Created : " & objF.DateCreated Ts.WriteLine "File Date Modified : " & objF.DateLastModified Ts.WriteLine "File Date Accessed : " & objF.DateLastAccessed Ts.WriteLine "Folder Type : " & objF.Type Ts.WriteLine Ln1 & "Folder Counter : " & Ct1 & Ln1 & "File Counter : " & Ct2 Ts.WriteBlankLines(2) Next Exit Function End Function '''' Function ConvertFileSize If objF.Size < 999999 Then fVar1 = Left(objF.Size,3) fVar1 = "File Size : " & fVar1 & " KB" End If If objF.Size > 1000000 Then fVar1 = objF.Size /MB : fVar1 = Left(fVar1,4) fVar1 = "File Size : " & fVar1 & " MB" End If If objF.Size > 1000000000 Then fVar1 = objF.Size /GB : fVar1 = Left(fVar1,4) fVar1 = "File Size : " & fVar1 & " GB" End If Exit Function End Function '''' Function FinishScript Time2 = Timer() Time3 = Time1 - Time2 Time3 = Replace(Time3,"-","") If Time3 < 60 Then Time3 = Left(Time3,4) Time3 = Time3 & " Seconds" Else Time3 = Time3 / 60 Time3 = Left(Time3,4) Time3 = Time3 & " Minutes" End If Ts.WriteLine Ln1 & "Folder Total : " & Ct1 Ts.WriteLine Ln1 & "File Total : " & Ct2 Ts.WriteLine Ln1 & "Script Time : " & Time3 Ts.Close '''' ASK IF USER WANT TO OPEN FILE Q1 = Act.Popup (Space(7) & "Completed Search" & vbCrLf & "Folder Total : " & Ct1 & vbCrLf &_ "File Total : " & Ct2 & vbCrLf & "Script Time : " & Time3 & vbCrLf &_ "Did You Want To Run This File?" & vbCrLf & FileRpt & vbCrLf &_ "If Nothing Is Selected In The" & vbCrLf & "Defualt Time Out, Of 5 Minute" & vbCrLf &_ "This Will Then Close And Exit", 301,"Completed Script", 4 + 64) If Q1 = VbYes Then : Act.Run(FileRpt) : End If If Q1 = -1 Then : On Error Goto 0 : End If Exit Function End Function Link to comment Share on other sites More sharing options...
spazmire11 Posted February 28, 2006 Share Posted February 28, 2006 quite simalerly to a cd drive finding loop this can be done with a single line:FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\* dir %%i: /b >> %systemdrive%\listforme.txt:*all on one linethis puts the output in the file listforme.txt on your main drive, beware this will also list the contents of cds and floppys if you have them in their drives at the time. if you dont want that remove the drive letter from the parentheses Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 28, 2006 Share Posted February 28, 2006 Here is a the VBs script that will search all hard drives on the local computerSave as ListAll.VbsWhat I added to the original script I posted. This only checks to see if it a hard drive, floppy drives and CD or DVD drives do not get check with this loop For Each strDrv In Drv If strDrv.DriveType = 2 Then ShowSubfolders Fso.GetFolder(strDrv) End If NextDim Act, CD, CName, colFiles, Ct1, Ct2,FileRpt, Fso, fVar1, fVar2, GB, Ln1, MB, objF, Ts, UNameDim Subfolder , SubFDC, SubFDLA, SubFDrv, SubFDLM, SubFName, SubFPath, SubFType, ZCDDim Time1, Time2, Time3Time1 = Timer() Set Fso = CreateObject("Scripting.FileSystemObject") Set Act = CreateObject("Wscript.Shell") CD = Act.CurrentDirectory ZCD = CD : ZCD = Split(ZCD,":") CName = Act.ExpandEnvironmentStrings("%ComputerName%") UName = Act.ExpandEnvironmentStrings("%UserName%") Ln1 = Space(2) & Chr(171) & " ----------- " & Chr(187) & Space(2) MB = 1024 * 1024 : GB = MB * MB FileRpt = (CName & "_DirList.Txt") Ct1 = 0 : Ct2 = 0 Set Ts = Fso.CreateTextFile(FileRpt) Ts.WriteLine Now() & Ln1 & UName & Ln1 ' Ts.WriteBlankLines(2)'''' START THE SEARCH THREW THE PARENT FOLDER AND SUB FOLDERDim Drv, strDrvSet Drv = Fso.Drives For Each strDrv In Drv If strDrv.DriveType = 2 Then ShowSubfolders Fso.GetFolder(strDrv) End If Next FinishScriptFunction ShowSubFolders(Folder)On Error Resume Next For Each Subfolder in Folder.SubFolders Ct1 = Ct1 + 1 SubFDrv = "Folder Drive : " & Subfolder.Drive SubFPath = "Folder Path : " & Subfolder.Path SubFName = "Folder Name : " & Subfolder.Name Set colFiles = Subfolder.Files MakeReport ShowSubFolders Subfolder Next Exit Function End Function '''' Function MakeReport Set colFiles = Subfolder.Files For Each objF in colFiles Ct2 = Ct2 + 1 fVar1 = objF.Size ConvertFileSize Ts.WriteLine SubFDrv & vbCrLf & SubFPath & vbCrLf & SubFName Ts.WriteLine "File Name : " & objF.Name Ts.WriteLine fVar1 Ts.WriteLine "File Date Created : " & objF.DateCreated Ts.WriteLine "File Date Modified : " & objF.DateLastModified Ts.WriteLine "File Date Accessed : " & objF.DateLastAccessed Ts.WriteLine Ln1 & "Folder Counter : " & Ct1 & Ln1 & "File Counter : " & Ct2 Ts.WriteBlankLines(1) Next Exit Function End Function '''' Function ConvertFileSize If objF.Size < 999999 Then fVar1 = Left(objF.Size,3) fVar1 = "File Size : " & fVar1 & " KB" End If If objF.Size > 1000000 Then fVar1 = objF.Size /MB : fVar1 = Left(fVar1,4) fVar1 = "File Size : " & fVar1 & " MB" End If If objF.Size > 1000000000 Then fVar1 = objF.Size /GB : fVar1 = Left(fVar1,4) fVar1 = "File Size : " & fVar1 & " GB" End If Exit Function End Function '''' Function FinishScript Time2 = Timer() Time3 = Time1 - Time2 Time3 = Replace(Time3,"-","") If Time3 < 60 Then Time3 = Left(Time3,4) Time3 = Time3 & " Seconds" Else Time3 = Time3 / 60 Time3 = Left(Time3,4) Time3 = Time3 & " Minutes" End If Ts.WriteLine Ln1 & "Folder Total : " & Ct1 Ts.WriteLine Ln1 & "File Total : " & Ct2 Ts.WriteLine Ln1 & "Script Time : " & Time3 Ts.Close '''' ASK IF USER WANT TO OPEN FILE Q1 = Act.Popup (Space(7) & "Completed Search" & vbCrLf & "Folder Total : " & Ct1 & vbCrLf &_ "File Total : " & Ct2 & vbCrLf & "Script Time : " & Time3 & vbCrLf &_ "Did You Want To Run This File?" & vbCrLf & FileRpt & vbCrLf &_ "If Nothing Is Selected In The" & vbCrLf & "Defualt Time Out, Of 5 Minute" & vbCrLf &_ "This Will Then Close And Exit", 301,"Completed Script", 4 + 64) If Q1 = VbYes Then : Act.Run(FileRpt) : End If If Q1 = -1 Then : On Error Goto 0 : End If Exit Function End Function Link to comment Share on other sites More sharing options...
eyeball Posted February 28, 2006 Author Share Posted February 28, 2006 wow thank you ever so much guys im going to have to try and get my head around these cos i really want to move onto vbs scripting Link to comment Share on other sites More sharing options...
thorus Posted March 9, 2006 Share Posted March 9, 2006 Or you could use AutoIT scripts to do this (compiled).There's a lot of usefull aplications written in AutoIt (it's like a basic language).Try a Google for AutoIT. Link to comment Share on other sites More sharing options...
LLXX Posted March 10, 2006 Share Posted March 10, 2006 Easiest way would be the batch file:for %a in ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ) do dir %a:\ /a /b /s >> c:\filelist.txt(Edit the batch file to only include the drives you want) Link to comment Share on other sites More sharing options...
Yzöwl Posted March 10, 2006 Share Posted March 10, 2006 (edited) This is how I would do it…ListEm.cmd@ECHO OFF &SETLOCAL ENABLEEXTENSIONSFOR /F %%? in ('MOUNTVOL ^|FIND ":\" ^|FIND /V "A:\"') DO IF EXIST %%?* (CALL :SUB %%?)ENDLOCAL &GOTO :EOF:SUBSET "LET=%1"SET "OUT=%1_%LET:~0,1%_LIST_.TXT"DIR/B/ON/A-D-H %1 >%OUT% 2>NUL ||TYPE NUL>%OUT%FOR /F "DELIMS=" %%? IN ('DIR/B/S/ON/AD-H %1 ^2^>NUL ^|SORT') DO IF ERRORLEVEL 0 ( DIR/B/ON/A-D-H %%? >NUL 2>&1 &&( >>%OUT% ECHO/ >>%OUT% ECHO/%%? >>%OUT% DIR/B/ON/A-D-H %%? ) )GOTO :EOFThe file could be shortened a little, but I prefer the safeguards and format of the resulting files!Each drive will hold the resulting directory listing text file at its root<Edit>NoteThis version deliberately ignores hidden files and folders.</Edit> Edited March 10, 2006 by Yzöwl Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now