Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: List Files in Folder With Ignore List

30 Jan 2011   #1

Windows 7 Ultimate 64-bit
 
 
List Files in Folder With Ignore List

Edit: Sorry I made the topic an forgot to change the title. Should be: "List Files in Folder With Ignore List" or something along those lines.

I'm a game server admin. What I want to do is generate a text file which will be used when I launch the server. An example of the text file I want to produce is here:

Code:
sv_name "PlayMyServer" 
sv_maxplayers 16
sv_mapcycle_add wizard ctf3
sv_mapcycle_add bloodgulch ctf3
sv_mapcycle_begin
Line 1 and 2 will be hard coded into the script. In fact, this section will have more lines but for this example, I've cut it down. Lines 3 and 4 are codes that add all maps to the server: wizard and bloodgulch. These are *.map files. Line 5, like lines 1 and 2, are to be hard coded.

The map files are in the \maps subdirectory of the game. What I'm looking to do, is create a batch file that will generate the above text. That is, getting a list of map files in the \maps directory and concatenating it with the proper text before and after. I also want to have the .map extension removed from the lists.

The \maps subdirectory has a few *.map files that aren't actual maps, in fact I don't know what they are. So, I would like to be able to allow for exclusions, which I will hard code as well. (i.e.: ui.map, sounds.map)

Note that this script will probably be saved somewhere in the Quick Launch folder and I want to specify the location of the output and the name of the file. It will be in a text file format.

If you can help me with this, thanks.

EDIT: I've found code that partially does what I want it to do. However, there are some problems:

Code:
On Error Resume Next
  Dim fso, folder, files, NewsFile,sFolder
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  sFolder = "C:\Users\Josh\Desktop\Maps\"
  If sFolder = "" Then
      Wscript.Echo "No Folder parameter was passed"
      Wscript.Quit
  End If
  Set NewFile = fso.CreateTextFile(sFolder&"\test.txt", True)
  Set folder = fso.GetFolder(sFolder)
  Set files = folder.Files
  
  NewFile.WriteLine("sv_maxplayers 16")
  
  For each folderIdx In files
    NewFile.WriteLine("sv_mapcycle_add " & folderIdx.Name & " ctf3")
  Next
  
  NewFile.WriteLine("sv_mapcycle_begin")
  NewFile.Close
Problems:
  1. I had to remove the first line with sv_name "MyServer", probably because of the fact that this has quotations in it. Otherwise the script wouldn't even run.
  2. the *.map extension is still shown. It needs to be removed.
  3. I need to allow for an exclusion file list. The files excluded will all be listed.



My System SpecsSystem Spec
.

30 Jan 2011   #2

Windows 7 Pro
 
 

DIR "D:\Data\" /s > "D:\List.txt"

This script will make a text listing all files in a folder.

D:\Data is where the folder is located and D is the drive where the text file "List" will be created. Note Windows 7 will NOT allow the text file to be created on C-drive.

You may have to edit to get what you want in the text files. I have found this script to be very useful.
My System SpecsSystem Spec
30 Jan 2011   #3

Windows 7 Ultimate 64-bit
 
 

Quote   Quote: Originally Posted by huffman View Post
Note Windows 7 will NOT allow the text file to be created on C-drive.
Wrong. My script creates a text file just fine on the C:\ drive. Maybe you mean it cannot create a text file on the root of the C:\ drive? That one I haven't tried, or maybe this is just specific to batch files? Not sure. But anyway, I say my script works fine to create a file, but I'm still not getting the desired output.


Quote   Quote: Originally Posted by huffman View Post
DIR "D:\Data\" /s > "D:\List.txt"
Tried it. This is way too much information than what I needed. This is more or less like going directly into the command prompt and just typing DIR in the directory. Not what I wanted. In fact, using /B instead of /S would just extract the names of the files, although the extensions would still be there.

A script is really what I need. What I have ALMOST works the way I want it to, just need someone with scripting knowledge to help finish it off. See the 3 problems listed on the original post.
My System SpecsSystem Spec
.


30 Jan 2011   #4

Windows 7 Ultimate 64-bit
 
 

Here is my updated code after some Google searching. I've hit a wall. I also attempted add to it.

Code:
On Error Resume Next
  Dim fso, folder, files, NewsFile,sFolder
  
  Set fso = CreateObject("Scripting.FileSystemObject")
  sFolder = "C:\Users\Josh\Desktop\Maps\"
  If sFolder = "" Then
      Wscript.Echo "No Folder parameter was passed"
      Wscript.Quit
  End If
  Set NewFile = fso.CreateTextFile(sFolder&"\maplist.txt", True)
  Set folder = fso.GetFolder(sFolder)
  Set files = folder.Files
  
  NewFile.WriteLine("sv_name " & Chr(34) & "MyServer" & Chr(34))
  NewFile.WriteLine("sv_maxplayers 16")
  
  For each folderIdx In files
    If (InStr(folderIdx.Name," "))
      NewFile.WriteLine("sv_mapcycle_add " & Chr(34) & Replace(folderIdx.Name,".map","") & Chr(34) & " ctf3")
    Else
      NewFile.WriteLine("sv_mapcycle_add " & Replace(folderIdx.Name,".map","") & " ctf3")
    End If
  Next
  
  NewFile.WriteLine("sv_mapcycle_begin")
  NewFile.Close
What's fixed:
  • I've figured out how to remove the file extensions. It works but it's not perfect. I use the Replace method to find ".map" in every string and replace it with nothing (or ""), which is fine because every file has the exact same extension.
  • I've figured out how to display quotations on the screen by using Chr(34).

What I still need help with is:
  • As you can see, within the For/Next Loop, I've implemented an If function. The goal is to put the text in quotations IF it contains a space. Apparently it doesn't seem to like that. I'm using the InStr method. Maybe I'm using it incorrectly. This If function I've added causes the script to break and there ends up being no file outputted.
  • I also have no idea how to implement an exclusion list. In otherwords, which maps to ignore by explicitly typing the file names in the script file.
Any help would be appreciated. Thanks.
My System SpecsSystem Spec
30 Jan 2011   #5

Windows XP
 
 

Try this batch file:

Code:
@echo off
Set "myFolder=C:\Users\Josh\Desktop\Maps\"
Set "ExcludeFile=C:\Users\Josh\Desktop\Exclude.txt"
>maplist.txt type nul
>>maplist.txt echo sv_name "MyServer"
>>maplist.txt echo sv_maxplayers 16
for /f %%f in ('dir /b "%myFolder%"') do (
    >nul 2>&1 find /i "%%f" %ExcludeFile%
    if ERRORLEVEL 1 (
        >>maplist.txt echo sv_mapcycle_add "%%~nf" ctf3
    )
)
>>maplist.txt echo sv_mapcycle_begin
Place the names of the files you want to exclude in the "C:\Users\Josh\Desktop\Exclude.txt" file.

HTH
My System SpecsSystem Spec
Reply

 List Files in Folder With Ignore List




Thread Tools



Similar help and support threads for2: List Files in Folder With Ignore List
Thread Forum
Solved List of REG Files Customization
Folder Details List - definitions Microsoft Office
Yahoo Messenger Ignore List Software
Solved List of generic folder names, like %appdata%? General Discussion
List of Files General Discussion
Folder view - list (file names cut off) General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 02:19 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33