I have developed a routine which prepares a directory listing for a specific
folder and save this information into a text file. This text file would be
used to send the required files via SFTP to a unix server.

My problem is that the case of the file name changes to lower case. For
example, the file name would appear in the folder as OPICS_Greeks.txt but
would appears as opics_greeks.txt in the text file. How can I retain the
original file name structure in the text file?

Below is the snippet:-

Set objTextFile = objFSO.OpenTextFile _
(StrFileName, ForAppending, True)

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strLocalFolder & "'} Where " _
& "ResultClass = CIM_DataFile")

For Each objFile In colFileList
' Define Short Name
StrFile = Len (objfile.Name)
StrDiff = (StrFile - strStart) + 1
ShortName = MID(objfile.name, strStart, StrDiff)
'Write Files to be transmitted to Text file
objTextFile.WriteLine ShortName
Next

'Close Transmit Text File
objTextFile.close

Re: Directory Listing by Pegasus

Pegasus
Thu Jul 10 00:20:34 CDT 2008


"Ken" <Enygma@Netfix.com> wrote in message
news:D3BA784E-FC19-41B2-B059-85B215C348A1@microsoft.com...
>I have developed a routine which prepares a directory listing for a
>specific
> folder and save this information into a text file. This text file would be
> used to send the required files via SFTP to a unix server.
>
> My problem is that the case of the file name changes to lower case. For
> example, the file name would appear in the folder as OPICS_Greeks.txt but
> would appears as opics_greeks.txt in the text file. How can I retain the
> original file name structure in the text file?
>
> Below is the snippet:-
>
> Set objTextFile = objFSO.OpenTextFile _
> (StrFileName, ForAppending, True)
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colFileList = objWMIService.ExecQuery _
> ("ASSOCIATORS OF {Win32_Directory.Name='" & strLocalFolder & "'} Where
> " _
> & "ResultClass = CIM_DataFile")
>
> For Each objFile In colFileList
> ' Define Short Name
> StrFile = Len (objfile.Name)
> StrDiff = (StrFile - strStart) + 1
> ShortName = MID(objfile.name, strStart, StrDiff)
> 'Write Files to be transmitted to Text file
> objTextFile.WriteLine ShortName
> Next
>
> 'Close Transmit Text File
> objTextFile.close

Use the File System object instead of WMI to obtain a list of your
files. It preserves the case of the file names.

BTW, the statement
ShortName = Mid(objFile.name, strStart, StrDiff)
is unlikely to work. Not only is strStart undefined but it needs to
be an integer, not a string.



Re: Directory Listing by Enygma

Enygma
Thu Jul 10 12:54:02 CDT 2008

Thanks for your insight.

Would you be able to guide me to some sample coding using file system object?

As for your observation, the coding convention was incorrect as the
variables are integer. Also, that was only a portion of the actual script,
the strStart variable was defined in the original script. I have, however,
redefine the variable name to show as intStart as well as the other variables
in that computation.

Thanks

"Pegasus (MVP)" wrote:

>
> "Ken" <Enygma@Netfix.com> wrote in message
> news:D3BA784E-FC19-41B2-B059-85B215C348A1@microsoft.com...
> >I have developed a routine which prepares a directory listing for a
> >specific
> > folder and save this information into a text file. This text file would be
> > used to send the required files via SFTP to a unix server.
> >
> > My problem is that the case of the file name changes to lower case. For
> > example, the file name would appear in the folder as OPICS_Greeks.txt but
> > would appears as opics_greeks.txt in the text file. How can I retain the
> > original file name structure in the text file?
> >
> > Below is the snippet:-
> >
> > Set objTextFile = objFSO.OpenTextFile _
> > (StrFileName, ForAppending, True)
> >
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> >
> > Set colFileList = objWMIService.ExecQuery _
> > ("ASSOCIATORS OF {Win32_Directory.Name='" & strLocalFolder & "'} Where
> > " _
> > & "ResultClass = CIM_DataFile")
> >
> > For Each objFile In colFileList
> > ' Define Short Name
> > StrFile = Len (objfile.Name)
> > StrDiff = (StrFile - strStart) + 1
> > ShortName = MID(objfile.name, strStart, StrDiff)
> > 'Write Files to be transmitted to Text file
> > objTextFile.WriteLine ShortName
> > Next
> >
> > 'Close Transmit Text File
> > objTextFile.close
>
> Use the File System object instead of WMI to obtain a list of your
> files. It preserves the case of the file names.
>
> BTW, the statement
> ShortName = Mid(objFile.name, strStart, StrDiff)
> is unlikely to work. Not only is strStart undefined but it needs to
> be an integer, not a string.
>
>
>

Re: Directory Listing by Pegasus

Pegasus
Thu Jul 10 14:36:20 CDT 2008

Try this:
strLocalFolder = "d:\Temp"
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oFile In oFSO.GetFolder(strLocalFolder).Files
WScript.Echo oFile.Name
Next


"Ken" <Enygma@Netfix.com> wrote in message
news:33314A1E-1B50-4CF9-966E-63E1A52F7F83@microsoft.com...
> Thanks for your insight.
>
> Would you be able to guide me to some sample coding using file system
> object?
>
> As for your observation, the coding convention was incorrect as the
> variables are integer. Also, that was only a portion of the actual script,
> the strStart variable was defined in the original script. I have, however,
> redefine the variable name to show as intStart as well as the other
> variables
> in that computation.
>
> Thanks
>
> "Pegasus (MVP)" wrote:
>
>>
>> "Ken" <Enygma@Netfix.com> wrote in message
>> news:D3BA784E-FC19-41B2-B059-85B215C348A1@microsoft.com...
>> >I have developed a routine which prepares a directory listing for a
>> >specific
>> > folder and save this information into a text file. This text file would
>> > be
>> > used to send the required files via SFTP to a unix server.
>> >
>> > My problem is that the case of the file name changes to lower case. For
>> > example, the file name would appear in the folder as OPICS_Greeks.txt
>> > but
>> > would appears as opics_greeks.txt in the text file. How can I retain
>> > the
>> > original file name structure in the text file?
>> >
>> > Below is the snippet:-
>> >
>> > Set objTextFile = objFSO.OpenTextFile _
>> > (StrFileName, ForAppending, True)
>> >
>> > Set objWMIService = GetObject("winmgmts:" _
>> > & "{impersonationLevel=impersonate}!\\" & strComputer &
>> > "\root\cimv2")
>> >
>> > Set colFileList = objWMIService.ExecQuery _
>> > ("ASSOCIATORS OF {Win32_Directory.Name='" & strLocalFolder & "'}
>> > Where
>> > " _
>> > & "ResultClass = CIM_DataFile")
>> >
>> > For Each objFile In colFileList
>> > ' Define Short Name
>> > StrFile = Len (objfile.Name)
>> > StrDiff = (StrFile - strStart) + 1
>> > ShortName = MID(objfile.name, strStart, StrDiff)
>> > 'Write Files to be transmitted to Text file
>> > objTextFile.WriteLine ShortName
>> > Next
>> >
>> > 'Close Transmit Text File
>> > objTextFile.close
>>
>> Use the File System object instead of WMI to obtain a list of your
>> files. It preserves the case of the file names.
>>
>> BTW, the statement
>> ShortName = Mid(objFile.name, strStart, StrDiff)
>> is unlikely to work. Not only is strStart undefined but it needs to
>> be an integer, not a string.
>>
>>
>>



Re: Directory Listing by Enygma

Enygma
Thu Jul 10 17:11:03 CDT 2008

Thanks... This indeed solved my problem as I sending files to an FTP server
which required the file names to be specific.



"Pegasus (MVP)" wrote:

> Try this:
> strLocalFolder = "d:\Temp"
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> For Each oFile In oFSO.GetFolder(strLocalFolder).Files
> WScript.Echo oFile.Name
> Next
>
>
> "Ken" <Enygma@Netfix.com> wrote in message
> news:33314A1E-1B50-4CF9-966E-63E1A52F7F83@microsoft.com...
> > Thanks for your insight.
> >
> > Would you be able to guide me to some sample coding using file system
> > object?
> >
> > As for your observation, the coding convention was incorrect as the
> > variables are integer. Also, that was only a portion of the actual script,
> > the strStart variable was defined in the original script. I have, however,
> > redefine the variable name to show as intStart as well as the other
> > variables
> > in that computation.
> >
> > Thanks
> >
> > "Pegasus (MVP)" wrote:
> >
> >>
> >> "Ken" <Enygma@Netfix.com> wrote in message
> >> news:D3BA784E-FC19-41B2-B059-85B215C348A1@microsoft.com...
> >> >I have developed a routine which prepares a directory listing for a
> >> >specific
> >> > folder and save this information into a text file. This text file would
> >> > be
> >> > used to send the required files via SFTP to a unix server.
> >> >
> >> > My problem is that the case of the file name changes to lower case. For
> >> > example, the file name would appear in the folder as OPICS_Greeks.txt
> >> > but
> >> > would appears as opics_greeks.txt in the text file. How can I retain
> >> > the
> >> > original file name structure in the text file?
> >> >
> >> > Below is the snippet:-
> >> >
> >> > Set objTextFile = objFSO.OpenTextFile _
> >> > (StrFileName, ForAppending, True)
> >> >
> >> > Set objWMIService = GetObject("winmgmts:" _
> >> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> >> > "\root\cimv2")
> >> >
> >> > Set colFileList = objWMIService.ExecQuery _
> >> > ("ASSOCIATORS OF {Win32_Directory.Name='" & strLocalFolder & "'}
> >> > Where
> >> > " _
> >> > & "ResultClass = CIM_DataFile")
> >> >
> >> > For Each objFile In colFileList
> >> > ' Define Short Name
> >> > StrFile = Len (objfile.Name)
> >> > StrDiff = (StrFile - strStart) + 1
> >> > ShortName = MID(objfile.name, strStart, StrDiff)
> >> > 'Write Files to be transmitted to Text file
> >> > objTextFile.WriteLine ShortName
> >> > Next
> >> >
> >> > 'Close Transmit Text File
> >> > objTextFile.close
> >>
> >> Use the File System object instead of WMI to obtain a list of your
> >> files. It preserves the case of the file names.
> >>
> >> BTW, the statement
> >> ShortName = Mid(objFile.name, strStart, StrDiff)
> >> is unlikely to work. Not only is strStart undefined but it needs to
> >> be an integer, not a string.
> >>
> >>
> >>
>
>
>