JOSHSKORN Posted April 5, 2008 Share Posted April 5, 2008 the echo. puts the blank line, your other option would be to putif exist c:\maplist.txt del c:\maplist.txtwhich would delete the file so there would be nothing to append to.OK out of my 3 echo occurrences I had, I just took a guess at which one you meant and I got it to work correctly. Plus, the coding makes a little more sense to me. I figured deleting the file would be the way to go, anyway. Thanks!@echo offif exist c:\maplist.txt del c:\maplist.txtfor /f "delims=*" %%f in ('dir /s /a /b "C:\Users\user1\Documents\Backup Files\Halo\Halo CE Maps\"') do echo %%~nf >> c:\maplist.txtexit Link to comment Share on other sites More sharing options...
Yzöwl Posted April 5, 2008 Share Posted April 5, 2008 This is how I'd do it:@Echo off>C:\maplist.txt Type NulPushd C:\Users\User1\Documents\Backup Files\Halo\Halo CE MapsFor /f "delims=" %%# In ('dir/b/s/a-d') Do >>C:\maplist.txt Echo:%%~n#Write an empty output file first, then perform the commands.You'll notice I've used -d to select only files. This is because removing extensions from files and directories you'd be unable to differentiate which was which in your output file. Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 5, 2008 Share Posted April 5, 2008 Here is a VBS script that will list the Halo folder and write the text file you want.I added 3 lines of code for making the numbers appear 001, 002 Etc.Save As ListHalo.vbsDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim F1, F2, F3,TS Set TS = Fso.CreateTextFile("C:\maplist.txt") Set F1 = Fso.GetFolder(" C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps") For Each F2 In F1.Files F3 = F3 + 1 If Len(F3) = 1 Then F3 = "00" & F3 If Len(F3) = 2 Then F3 = "0" & F3 If Len(F3) = 3 Then F3 = F3 TS.WriteLine F3 & " " & F2.Name Next TS.Close() Link to comment Share on other sites More sharing options...
JOSHSKORN Posted April 5, 2008 Share Posted April 5, 2008 Here is a VBS script that will list the Halo folder and write the text file you want.I added 3 lines of code for making the numbers appear 001, 002 Etc.Save As ListHalo.vbsDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim F1, F2, F3,TS Set TS = Fso.CreateTextFile("C:\maplist.txt") Set F1 = Fso.GetFolder(" C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps") For Each F2 In F1.Files F3 = F3 + 1 If Len(F3) = 1 Then F3 = "00" & F3 If Len(F3) = 2 Then F3 = "0" & F3 If Len(F3) = 3 Then F3 = F3 TS.WriteLine F3 & " " & F2.Name Next TS.Close()Well that's cool. It's always nice to see a different way of doing things. However, this code produced this error message and I'll just type it out:Script: C:\Users\user1\Desktop\ListHalo.vbsLine: 4Char: 1Error: Path not foundCode: 800A004CSource: Microsoft VBScript runtime error.The text file is created but blank. I'm interested in seeing what this code is suppose to do. Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 5, 2008 Share Posted April 5, 2008 It was a sloppy cut and paste there is a extra space in the pathSet F1 = Fso.GetFolder(" C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps")Set F1 = Fso.GetFolder("C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps")You have to make sure you have that path, or change it to what ever path you wantSet F1 = Fso.GetFolder("C:\WINDOWS\system32") Link to comment Share on other sites More sharing options...
JOSHSKORN Posted April 5, 2008 Share Posted April 5, 2008 It was a sloppy cut and paste there is a extra space in the pathDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim F1, F2, F3,TSSet TS = Fso.CreateTextFile("C:\maplist.txt")Set F1 = Fso.GetFolder("C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps") For Each F2 In F1.Files F3 = F3 + 1 If Len(F3) = 1 Then F3 = "00" & F3 If Len(F3) = 2 Then F3 = "0" & F3 If Len(F3) = 3 Then F3 = F3 TS.WriteLine F3 & " " & F2.Name Next TS.Close()I see it now. I just went ahead and plopped in the correct version of the code. I'm surprised I didn't see that, actually. Anywho, I like both versions, that is, the batch file, and the VB script. Not only can I now generate a list of Halo CE (a separate version of Halo that allows you to play custom content) maps I have, but I can now say with ease that wow I just have too many! Just 1,069, that's all. lolI've been wanting to learn a little VBScript. This'll help in more ways than one. Thanks to everyone! Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 6, 2008 Share Posted April 6, 2008 (edited) Here is the same script that list a few more detailsDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim F1, F2, F3, Size, TS, V1, V2 V1 = Chr(160) & Chr(187) & Chr(160) Set TS = Fso.CreateTextFile("C:\maplist.txt") Set F1 = Fso.GetFolder("C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps") For Each F2 In F1.Files F3 = F3 + 1 If Len(F3) = 1 Then F3 = "000" & F3 If Len(F3) = 2 Then F3 = "00" & F3 If Len(F3) = 3 Then F3 = "0" & F3 If Len(F3) = 4 Then F3 = F3 If F2.Size =< 1048576 Then Size = FormatNumber(F2.Size/1024,2) & "KB" If F2.Size >= 1048576 Then Size = FormatNumber(F2.Size/1048576,2) & " MB" If F2.Size >= 1073741824 Then Size = FormatNumber(F2.Size/1073741824,2) & " GB" V2 = V2 + F2.Size TS.WriteLine F3 & " " & F2.Name TS.WriteLine "Created " & V1 & F2.DateCreated TS.WriteLine "Accessed " & V1 & F2.DateLastAccessed TS.WriteLine "Modified " & V1 & F2.DateLastModified TS.WriteLine "FileSize " & V1 & Size & vbCrLf Next Size = "" If V2 =< 1048576 Then Size = FormatNumber(V2/1024,2) & "KB" If V2 >= 1048576 Then Size = FormatNumber(V2/1048576,2) & " MB" If V2 >= 1073741824 Then Size = FormatNumber(V2/1073741824,2) & " GB" TS.WriteLine "C:\WINDOWS\system32" TS.WriteLine "TotalSize" & V1 & Size & vbCrLf TS.Close() CreateObject("Wscript.Shell").Run("C:\maplist.txt") Edited April 6, 2008 by gunsmokingman Link to comment Share on other sites More sharing options...
JOSHSKORN Posted April 6, 2008 Share Posted April 6, 2008 Here is the same script that list a few more detailsDim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")Dim F1, F2, F3, Size, TS, V1, V2 V1 = Chr(160) & Chr(187) & Chr(160) Set TS = Fso.CreateTextFile("C:\maplist.txt") Set F1 = Fso.GetFolder("C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps") For Each F2 In F1.Files F3 = F3 + 1 If Len(F3) = 1 Then F3 = "000" & F3 If Len(F3) = 2 Then F3 = "00" & F3 If Len(F3) = 3 Then F3 = "0" & F3 If Len(F3) = 4 Then F3 = F3 If F2.Size =< 1048576 Then Size = FormatNumber(F2.Size/1024,2) & "KB" If F2.Size >= 1048576 Then Size = FormatNumber(F2.Size/1048576,2) & " MB" If F2.Size >= 1073741824 Then Size = FormatNumber(F2.Size/1073741824,2) & " GB" V2 = V2 + F2.Size TS.WriteLine F3 & " " & F2.Name TS.WriteLine "Created " & V1 & F2.DateCreated TS.WriteLine "Accessed " & V1 & F2.DateLastAccessed TS.WriteLine "Modified " & V1 & F2.DateLastModified TS.WriteLine "FileSize " & V1 & Size & vbCrLf Next Size = "" If V2 =< 1048576 Then Size = FormatNumber(V2/1024,2) & "KB" If V2 >= 1048576 Then Size = FormatNumber(V2/1048576,2) & " MB" If V2 >= 1073741824 Then Size = FormatNumber(V2/1073741824,2) & " GB" TS.WriteLine "C:\WINDOWS\system32" TS.WriteLine "TotalSize" & V1 & Size & vbCrLf TS.Close() CreateObject("Wscript.Shell").Run("C:\maplist.txt")cool. Where's the best place to go to learn all about VBScript, then? Should I just get a book on VBScripts from Wrox? Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 6, 2008 Share Posted April 6, 2008 Here is a good spot to learn about VBS scriptingThe Hey, Scripting Guy! Archive 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