I'm using the function glob from module glob to obtain a list of all
files in a directory that match a pattern. Unfortunately, some
filenames are in upper case, others are in lower case and yet others
are in mixed case. How can I do a case-insenstive glob that picks up
all files that match a string regardless of case? If its any help, I'm
running Python 2.3.4 under Windows XP.
Thomas Philips 4 9490
Just use os.path.normcase() on all of them.
import glob
import os
flist=glob.glob(mask)
flist=[os.path.normcase(f) for f in flist]
....
<insert your code here>
HTH,
Larry Bates
Syscon, Inc.
"Thomas Philips" <tk****@hotmail.com> wrote in message
news:b4**************************@posting.google.c om... I'm using the function glob from module glob to obtain a list of all files in a directory that match a pattern. Unfortunately, some filenames are in upper case, others are in lower case and yet others are in mixed case. How can I do a case-insenstive glob that picks up all files that match a string regardless of case? If its any help, I'm running Python 2.3.4 under Windows XP.
Thomas Philips tk****@hotmail.com (Thomas Philips) writes: I'm using the function glob from module glob to obtain a list of all files in a directory that match a pattern. Unfortunately, some filenames are in upper case, others are in lower case and yet others are in mixed case. How can I do a case-insenstive glob that picks up all files that match a string regardless of case? If its any help, I'm running Python 2.3.4 under Windows XP.
If it works the same as it does on Unix then you can use the [Xx] construct
for each of the characters, eg *[Ff][Oo][Oo]* but I'll bet there are better
ways to do the task.
Eddie
On 3 Jun 2004 09:59:36 -0700, tk****@hotmail.com (Thomas Philips)
declaimed the following in comp.lang.python: are in mixed case. How can I do a case-insenstive glob that picks up all files that match a string regardless of case? If its any help, I'm running Python 2.3.4 under Windows XP.
Unless XP has made a drastic change in the handling of file
names, you don't worry about them... flist = glob.glob("D*.*") flist
['desktop.ini', 'Dennis Lee Bieber.asc', 'Doc1.doc', 'DF297.pdf']
flist = glob.glob("d*.*") flist
['desktop.ini', 'Dennis Lee Bieber.asc', 'Doc1.doc', 'DF297.pdf']
Windows is a "case preserving, case insensitive" OS.
Well, actually I should modify that -- the Windows file explorer
tends to convert names in all "CAPS" into just first letter "Caps" when
displaying... But it is still all CAPS internally.
-- ================================================== ============ < wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < wu******@dm.net | Bestiaria Support Staff < ================================================== ============ < Home Page: <http://www.dm.net/~wulfraed/> < Overflow Page: <http://wlfraed.home.netcom.com/> <
Dennis Lee Bieber wrote: On 3 Jun 2004 09:59:36 -0700, tk****@hotmail.com (Thomas Philips) declaimed the following in comp.lang.python:
are in mixed case. How can I do a case-insenstive glob that picks up all files that match a string regardless of case? If its any help, I'm running Python 2.3.4 under Windows XP.
Unless XP has made a drastic change in the handling of file names, you don't worry about them...
flist = glob.glob("D*.*") flist
['desktop.ini', 'Dennis Lee Bieber.asc', 'Doc1.doc', 'DF297.pdf']
You can also make it cross platform by doing this:
flist = glob.glob("[dD]*.*")
Derek This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Newbie |
last post by:
Dear friends,
I am having a hard time understanding how to use a SELECT CASE in ASP. I
have used it in VB but never in ASP scripting.
Scenerio:
I have 2 textboxes on a form that I have to...
|
by: Robert Scheer |
last post by:
Hi.
In VBScript I can use a Select Case statement like that:
Select Case X
Case 1 to 10 'X is between 1 and 10
Case 11,14,16 'X is 11 or 14 or 16
End Select
|
by: ST |
last post by:
Hi, I'm trying to debug someone else's code, and I'm going thru this Select
Case statement. I'm having problems with the "OTHER" case...in that when the
first line of the case is false, it jumps...
|
by: cs168 |
last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as...
|
by: deanfamily11 |
last post by:
I've set up a case statement to have my program determine where on the
Cartesian plane a point the user enters is located. I keep getting the
C2051 error when I compile. Any help?
#include...
|
by: MLH |
last post by:
Suppose the following...
Dim A as Date
A=#7/24/2005#
I wish to compare value of A against 2 other values:
1) 8/1/2005
2) 9/1/2005
Which is better and why...
First:
|
by: Lauren Quantrell |
last post by:
Is there any speed/resource advantage/disadvantage in using
Select Case x
Case 1
Case 2
etc. many more cases...
End Select
VS.
|
by: John |
last post by:
Hi Folks,
I'm experimenting a little with creating a custom CEdit control so that
I can decide on what the user is allowed to type into the control. I
started off only allowing floating point...
|
by: Navodit |
last post by:
So I have some code like:
if (document.Insurance.State.selectedIndex == 1)
{
ifIll();
}
else if (document.Insurance.State.selectedIndex == 2)
{
elseKan();
}
|
by: clockworx05 |
last post by:
Hey guys i have this program that i need to write for class. here are the instructions:
Write a function called foo that asks the user for their age. Pass the age value to a function called...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |