Issue34627
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2018-09-11 08:26 by badrussians, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| test2.py | badrussians, 2018-09-11 08:26 | code, that in comment | ||
| Messages (3) | |||
|---|---|---|---|
| msg324996 - (view) | Author: (badrussians) | Date: 2018-09-11 08:26 | |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
print('');
import sys, os, subprocess, re, ctypes, tempfile, shutil, tarfile, urllib.request;
argsCount=len(sys.argv);
scriptDir = os.path.dirname(os.path.abspath(sys.argv[0]));
def FindFullPaths(strPattern, *orderedSearchDirs, \
findFile=True, findDir=False, \
ignoreCase=False, returnFirst=True):
print('# FindFullPaths__In');
result = [];
def resultAppendUnique(item):
if item not in result:
result.append(item);
pattern = re.compile(strPattern, \
re.IGNORECASE | re.DOTALL if ignoreCase else re.DOTALL);
isFound = False;
for searchDir in orderedSearchDirs:
print('#searchDir', searchDir, orderedSearchDirs, '\n');
for leafName in os.listdir(searchDir):
leafPath = os.path.join(searchDir, leafName);
isDir = os.path.isdir(leafPath);
isFound = (findDir and isDir or \
findFile and os.path.isfile(leafPath)) \
and pattern.search(leafName) is not None;
print('#leafPath:', leafPath, '\n'); #ERROR = output Last AND last time - no in output!
print('#isFound:', isFound); #ERROR = output First AND first time - no in output!
if isFound:
resultAppendUnique(leafPath);
if isDir and not (returnFirst and isFound):
for partLeafPath in FindFullPaths(strPattern, leafPath, \
findFile=findFile, findDir=findDir, \
ignoreCase=ignoreCase, returnFirst=returnFirst):
resultAppendUnique(partLeafPath);
isFound = True;
if returnFirst and isFound:
break;
if returnFirst and isFound:
break;
print('# FindFullPaths__Return');
return result;
FindFullPaths('^bat$', '/home/user/Рабочий стол/ttt');
print(sys.version);
#### OUTPUT: ####
'/home/user/Рабочий стол/test2.py'
# FindFullPaths__In
#searchDir /home/user/Рабочий стол/ttt ('/home/user/Рабочий стол/ttt',)
#leafPath: /home/user/Рабочий стол/ttt/BackupRestore.py
#isFound: False
#leafPath: /home/user/Рабочий стол/ttt/temp.py
#isFound: False
#leafPath: /home/user/Рабочий стол/ttt/Create ISO.py
#isFound: False
# FindFullPaths__Return
3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0]
###### Environment ######
Russian Ubuntu 18.04.1 and Kali 2018.3
PS: Ru:'/home/user/Рабочий стол' == Eng'/home/user/Desktop'
|
|||
| msg324998 - (view) | Author: Karthikeyan Singaravelan (xtreak) * ![]() |
Date: 2018-09-11 09:38 | |
Can you please describe the problem and the output you are expecting so that we can determine if it's a bug in Python or the logic of the code which will get better help from sites stackoverflow ? It will be helpful if you can do `tree` on the search directory if it's small so that it will be helpful to replicate the structure for test too. Please consider using 4 space instead of tabs as per PEP8 and semicolon is not needed at the end of statements. A little cleaned up version of the same program. #!/usr/bin/env python3 # -*- coding: utf-8 -*- print('') import sys, os, subprocess, re, ctypes, tempfile, shutil, tarfile, urllib.request argsCount=len(sys.argv) scriptDir = os.path.dirname(os.path.abspath(sys.argv[0])) def FindFullPaths(strPattern, *orderedSearchDirs, \ findFile=True, findDir=False, \ ignoreCase=False, returnFirst=True): print('# FindFullPaths__In') result = [] def resultAppendUnique(item): if item not in result: result.append(item) pattern = re.compile(strPattern, \ re.IGNORECASE | re.DOTALL if ignoreCase else re.DOTALL) isFound = False for searchDir in orderedSearchDirs: print('#searchDir', searchDir, orderedSearchDirs, '\n') for leafName in os.listdir(searchDir): leafPath = os.path.join(searchDir, leafName) isDir = os.path.isdir(leafPath) isFound = (findDir and isDir or \ findFile and os.path.isfile(leafPath)) \ and pattern.search(leafName) is not None print('#leafPath:', leafPath, '\n') #ERROR = output Last AND last time - no in output! print('#isFound:', isFound) #ERROR = output First AND first time - no in output! if isFound: resultAppendUnique(leafPath) if isDir and not (returnFirst and isFound): for partLeafPath in FindFullPaths(strPattern, leafPath, \ findFile=findFile, findDir=findDir, \ ignoreCase=ignoreCase, returnFirst=returnFirst): resultAppendUnique(partLeafPath) isFound = True; if returnFirst and isFound: break; if returnFirst and isFound: break; print('# FindFullPaths__Return') return result FindFullPaths('^bat$', '/tmp/') print(sys.version) Thanks |
|||
| msg324999 - (view) | Author: (badrussians) | Date: 2018-09-11 11:11 | |
Big Sorry - it is my mistake. In terminal I execute same file, but in other location. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:05 | admin | set | github: 78808 |
| 2018-09-11 11:11:47 | badrussians | set | status: open -> closed resolution: not a bug messages: + msg324999 stage: resolved |
| 2018-09-11 09:38:41 | xtreak | set | nosy:
+ xtreak messages: + msg324998 |
| 2018-09-11 08:26:50 | badrussians | create | |
