Case Sensitive file path matching in PythonIgnore case in glob() on LinuxHow can I represent an 'Enum' in Python?How can I safely create a nested directory in Python?How do I get the path of the current executed file in Python?How do I list all files of a directory?Way to create multiline comments in Python?What is the Python 3 equivalent of “python -m SimpleHTTPServer”How to find if directory exists in PythonPythonic way to retrieve case sensitive path?How do I find all files containing specific text on Linux?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
What happens when a metallic dragon and a chromatic dragon mate?
Is a car considered movable or immovable property?
Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Some basic questions on halt and move in Turing machines
What does "enim et" mean?
What are the advantages and disadvantages of running one shots compared to campaigns?
Is this food a bread or a loaf?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Why is the design of haulage companies so “special”?
What is GPS' 19 year rollover and does it present a cybersecurity issue?
Doomsday-clock for my fantasy planet
Weird behaviour when using querySelector
Does a dangling wire really electrocute me if I'm standing in water?
Does the average primeness of natural numbers tend to zero?
Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?
How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?
Are objects structures and/or vice versa?
Extreme, but not acceptable situation and I can't start the work tomorrow morning
Are white and non-white police officers equally likely to kill black suspects?
How to manage monthly salary
Is there a way to make member function NOT callable from constructor?
Why doesn't a const reference extend the life of a temporary object passed via a function?
When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?
Case Sensitive file path matching in Python
Ignore case in glob() on LinuxHow can I represent an 'Enum' in Python?How can I safely create a nested directory in Python?How do I get the path of the current executed file in Python?How do I list all files of a directory?Way to create multiline comments in Python?What is the Python 3 equivalent of “python -m SimpleHTTPServer”How to find if directory exists in PythonPythonic way to retrieve case sensitive path?How do I find all files containing specific text on Linux?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a directory with this path
Al Furjan/Al Furjan 2D 3D/3D/AZIZI tulip/file.jpg
I have another csv from which i am creating the path and the path becomes like this
Al Furjan/Al Furjan 2D 3D/3D/AZIZI Tulip/file.jpg
The path i am generating has T capital, but the actual directory has small t. How can i cater this issue with python, that it ignores the case sensitivity while searching through paths.
python-3.x directory
add a comment |
I have a directory with this path
Al Furjan/Al Furjan 2D 3D/3D/AZIZI tulip/file.jpg
I have another csv from which i am creating the path and the path becomes like this
Al Furjan/Al Furjan 2D 3D/3D/AZIZI Tulip/file.jpg
The path i am generating has T capital, but the actual directory has small t. How can i cater this issue with python, that it ignores the case sensitivity while searching through paths.
python-3.x directory
add a comment |
I have a directory with this path
Al Furjan/Al Furjan 2D 3D/3D/AZIZI tulip/file.jpg
I have another csv from which i am creating the path and the path becomes like this
Al Furjan/Al Furjan 2D 3D/3D/AZIZI Tulip/file.jpg
The path i am generating has T capital, but the actual directory has small t. How can i cater this issue with python, that it ignores the case sensitivity while searching through paths.
python-3.x directory
I have a directory with this path
Al Furjan/Al Furjan 2D 3D/3D/AZIZI tulip/file.jpg
I have another csv from which i am creating the path and the path becomes like this
Al Furjan/Al Furjan 2D 3D/3D/AZIZI Tulip/file.jpg
The path i am generating has T capital, but the actual directory has small t. How can i cater this issue with python, that it ignores the case sensitivity while searching through paths.
python-3.x directory
python-3.x directory
asked Mar 8 at 6:47
Ahsan MukhtarAhsan Mukhtar
248216
248216
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use a conjunction of fnmatch, re and os to do this:
import os
import fnmatch
import re
# translate the file name in a pattern
regex = fnmatch.translate('testit/testIT/testIT.txt')
# compile a case insensitive version of your this pattern
rec = re.compile(regex, re.IGNORECASE)
def listallfiles(path):
for (dirpath, dirnames, filenames) in os.walk(path):
for f in filenames:
yield(os.path.relpath(os.path.join(dirpath, f)))
found = [i for i in listallfiles('.') if rec.match(i)]
print(found)
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058072%2fcase-sensitive-file-path-matching-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a conjunction of fnmatch, re and os to do this:
import os
import fnmatch
import re
# translate the file name in a pattern
regex = fnmatch.translate('testit/testIT/testIT.txt')
# compile a case insensitive version of your this pattern
rec = re.compile(regex, re.IGNORECASE)
def listallfiles(path):
for (dirpath, dirnames, filenames) in os.walk(path):
for f in filenames:
yield(os.path.relpath(os.path.join(dirpath, f)))
found = [i for i in listallfiles('.') if rec.match(i)]
print(found)
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
add a comment |
You can use a conjunction of fnmatch, re and os to do this:
import os
import fnmatch
import re
# translate the file name in a pattern
regex = fnmatch.translate('testit/testIT/testIT.txt')
# compile a case insensitive version of your this pattern
rec = re.compile(regex, re.IGNORECASE)
def listallfiles(path):
for (dirpath, dirnames, filenames) in os.walk(path):
for f in filenames:
yield(os.path.relpath(os.path.join(dirpath, f)))
found = [i for i in listallfiles('.') if rec.match(i)]
print(found)
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
add a comment |
You can use a conjunction of fnmatch, re and os to do this:
import os
import fnmatch
import re
# translate the file name in a pattern
regex = fnmatch.translate('testit/testIT/testIT.txt')
# compile a case insensitive version of your this pattern
rec = re.compile(regex, re.IGNORECASE)
def listallfiles(path):
for (dirpath, dirnames, filenames) in os.walk(path):
for f in filenames:
yield(os.path.relpath(os.path.join(dirpath, f)))
found = [i for i in listallfiles('.') if rec.match(i)]
print(found)
You can use a conjunction of fnmatch, re and os to do this:
import os
import fnmatch
import re
# translate the file name in a pattern
regex = fnmatch.translate('testit/testIT/testIT.txt')
# compile a case insensitive version of your this pattern
rec = re.compile(regex, re.IGNORECASE)
def listallfiles(path):
for (dirpath, dirnames, filenames) in os.walk(path):
for f in filenames:
yield(os.path.relpath(os.path.join(dirpath, f)))
found = [i for i in listallfiles('.') if rec.match(i)]
print(found)
edited Mar 8 at 8:43
answered Mar 8 at 7:07
Louis CaronLouis Caron
997
997
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
add a comment |
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I found similar solution as well as others in this question: stackoverflow.com/questions/8151300/…
– Louis Caron
Mar 8 at 7:08
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
I tried that solutions, but none of them worked for me.
– Ahsan Mukhtar
Mar 8 at 7:45
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
Can you share an exmaple of it ?
– Ahsan Mukhtar
Mar 8 at 7:46
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
I have completely restarted it, the use of glob was misleading. I have rather used os.walk with an iterator.
– Louis Caron
Mar 8 at 8:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55058072%2fcase-sensitive-file-path-matching-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown