Jump to content

Help with a batch file.


Recommended Posts

the echo. puts the blank line, your other option would be to put

if exist c:\maplist.txt del c:\maplist.txt

which 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 off
if exist c:\maplist.txt del c:\maplist.txt
for /f "delims=*" %%f in ('dir /s /a /b "C:\Users\user1\Documents\Backup Files\Halo\Halo CE Maps\"') do echo %%~nf >> c:\maplist.txt
exit

Link to comment
Share on other sites


This is how I'd do it:

@Echo off
>C:\maplist.txt Type Nul
Pushd C:\Users\User1\Documents\Backup Files\Halo\Halo CE Maps
For /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

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.vbs

Dim 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

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.vbs

Dim 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.vbs

Line: 4

Char: 1

Error: Path not found

Code: 800A004C

Source: 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

It was a sloppy cut and paste there is a extra space in the path

Set 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 want

Set F1 = Fso.GetFolder("C:\WINDOWS\system32")

Link to comment
Share on other sites

It was a sloppy cut and paste there is a extra space in the path

Dim 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()

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. lol

I'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

Here is the same script that list a few more details

Dim 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 by gunsmokingman
Link to comment
Share on other sites

Here is the same script that list a few more details
Dim 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...