Login | |
|
 |
RE: Getting files from a folder - 5/7/2008 4:13:16 AM
|
|
 |
|
| |
Country73
Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
Change: SET objFolder = objFSO.GetFolder("C:\Test\") To just SET objFolder = objFSO.GetFolder("C:\Test") Then just add this to the end of what you have shown: FOR EACH objFiles1 IN objFiles wscript.echo objFiles1.Name NEXT
|
|
| |
|
|
|
 |
RE: Getting files from a folder - 5/7/2008 7:57:25 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Here is my guess. Look at the code where you make nFile: If PlcHlder = "Test1" Then FlOpt = "1" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test2" Then FlOpt = "2" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test3" Then FlOpt = "3" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test4" Then FlOpt = "4" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) End If What would happen if PlcHolder did not meet any of these requirements? What would nFile be? If that were the case, what would happen when execution hits this line? nFile.WriteLine("This file is correct")
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Getting files from a folder - 5/7/2008 8:26:57 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Ok, so I'm going to go through and just sort of stream of consciousness make some comments about what you have so far: You only need one FileSystemObject, not 3 Use the .Name property of the file object explicitly, so this: PlcHlder = Mid(objFiles1, 9, 5 becomes this: PlcHlder = Mid(objFiles1.Name, 9, 5 The naming of nFile has nothing to do with the If-Then, so take it out. This: If PlcHlder = "Test1" Then FlOpt = "1" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test2" Then FlOpt = "2" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test3" Then FlOpt = "3" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test4" Then FlOpt = "4" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) End If becomes this: If PlcHlder = "Test1" Then FlOpt = "1" ElseIf PlcHlder = "Test2" Then FlOpt = "2" ElseIf PlcHlder = "Test3" Then FlOpt = "3" ElseIf PlcHlder = "Test4" Then FlOpt = "4" End If Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) Now you can see that an if then is really kind of silly for this logic and a Select-Case would be better. So it becomes: Select Case PlcHlder Case "Test1" FlOpt = "1" Case "Test2" FlOpt = "2" Case "Test3" FlOpt = "3" Case "Test4" FlOpt = "4" End Select But wait..If you look closely, there is an easily defined pattern here. FlOpt is always the same as the last character of PlcHlder. So this would work: FlOpt = Right(PlcHlder, 1) So we can replace all of this: If PlcHlder = "Test1" Then FlOpt = "1" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test2" Then FlOpt = "2" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test3" Then FlOpt = "3" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) ElseIf PlcHlder = "Test4" Then FlOpt = "4" Set nFile = nFSO.CreateTextFile("C:\test\Summary " & PlcHlder & Ext, True) End If with this: FlOpt = Right(PlcHlder, 1) That's all I see right now. I don't think I addressed your specific question, but I'm not sure I understand it anyway. Could you explain in more detail what problem you are currently having?
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|