[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

Case sensitive?

I have the following command in a vbscript:

Set colFiles = objWMIService. ExecQuery("Select * from CIM_DataFile where Path = '\\PDF\\TEST\\'")

If a file with a .doc extentsion is found in this folder, we use word to open it and print it.  Within the document we have a footer that references the filename.

If the file name is, TestFile001.doc, the footer shows up in all lowercase.  If I open the file manually it shows up in the correct case, which is the same as the file name.

I know Windows is not case sensitive, but is there a way to preserve the case?

0
robrandon
Asked:
robrandon
  • 5
  • 2
  • 2
  • +2
1 Solution
 
David LeeCommented:
Hi robrandon,
> is there a way to preserve the case

The case should be the same unless something is manipulating it.  Of course you can always force the case to all upper or all lower if you want by using the LCase or UCase functions.

Cheers!
0
 
robrandonAuthor Commented:
Here, I've done more research.  Put some files in a folder called \pdf\test and run the script below.  It outputs everything in lowercase, regardless of the file name's case.

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

Set colFiles = objWMIService. ExecQuery("Select * from CIM_DataFile where Path = '\\PDF\\TEST\\'")
For Each objFile in colFiles
FileName   = objFile.Name
wscript.echo FileName
Next


0
 
Ryan ChongCommented:
>>I've done more research.  Put some files in a folder called \pdf\test and run the script below.  It outputs everything in lowercase, regardless of the file name's case.

It's because the Windows itself treat file name is same regardless of the uppercase or lowercase, it's not same as in Linux platform.

So, no worries about the case issue, i think.

regards
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
robrandonAuthor Commented:
But is there a way to get around this?  In my case it is important because the footer in the word document does not appear correctly.  But, if the word doc is opened manually, it shows up with the proper case.
0
 
Ryan ChongCommented:
I think it's not showing proper case, and showing the all in lowercase, may be it's handle by Windows itself (Who knows??....)

Btw, how you open and print the word document? Maybe we can get some clues from it how it change the case of your footer.

* PS: what if you put the file references at header?
0
 
robrandonAuthor Commented:
It doesn't matter if I put it in the header.  Part of my code is below.  If I open the document myself, it shows the proper case.  If I open it with the code below, it does not.  


Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open(InputPath)
objApp.PrintOut 0, , , OutputPath, , , , , , , 1
objApp.Quit False
0
 
RainUKCommented:
Is it essential that you use WMI service to retrieve the files in the folder? Is it because you are running the script to access remotely the specified folder?

I mean you can always opt for the FSO File Scripting Object and a UNC path name to the folder, which will return your filenames in case sensitive order e.g:

Dim oFSO As FileSystemObject
Dim oFolder As Folder
Dim oFileX As File


    Set oFSO = New FileSystemObject
    Set oFolder = oFSO.GetFolder("C:\FolderX")
   
    For Each oFileX In oFolder.Files
   
        Debug.Print oFileX.Name
   
    Next oFileX
0
 
robrandonAuthor Commented:
I used WMI because it was the only way I knew how (not a professional coder).  I tried putting your code in a test.vbs file and run it with cscript, but I get an error.  

0
 
RainUKCommented:
Try this script version

Dim oFSO, oFolder, oFileX

   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFolder = oFSO.CreateFolder("C:\MyTest")

   Also take a look at the MSDN article, it has loads of VB Script examples.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/sgprogrammingfilesystemobject.asp
0
 
robrandonAuthor Commented:
Sweet.  Using FileSystemObject worked.  It keeps the case.  Thanks RainUK.

0
 
SvenForkbeardCommented:
After playing with VBScript some, I have found a cheap-shot workaround for WMI's penchant of returning all-lowercase filenames.  Like RainUK said, use FileSystemObject instead--but use WMI first to search for the files, folders, and subfolders because it's more convenient. Then use the FileSystemObject's GetFile method to retrieve whatever target you are interested in and work with it in the script from there.  This approach works well with regular expressions or user input dialogs.

Why use this approach instead of using FileSystemObject to recursively search? Because this approach allows you to use only 8 lines of code instead of ~22 as found in the Microsoft Knowledge Base: http://support.microsoft.com/kb/185601.

Hope this helps someone!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now