## denniskhor -4

My question is :'

if my "[2009'07'12 @ 22'49'47] main page.jpg" store in "C:\image folder\", but the timestamp [2009'07'12 @ 22'49'47] will be inconsistent, so i wan use behind "main page.jpg" to find "[2009'07'12 @ 22'49'47] main page.jpg", and print the link like "C:\image folder\[2009'07'12 @ 22'49'47] main page.jpg" as output... hw to do it?

Thanks for help.

## woooee 814

Read the directory and then use os.stat to get file info. You will probably want to use one of st_atime, st_mtime, or st_ctime depending on which OS system you are on.

## denniskhor -4

i use pywinauto, so will be like tat... ur answer din point to my question...

## jlm699 320

i use pywinauto, so will be like tat... ur answer din point to my question...

Your grammar is atrocious, therefore your question makes no sense. It is unlikely that anyone will be willing or able to answer it in its current form. I suggest revising your question and asking in a clear, concise manner using proper grammar and spelling.

## Arrorn -4

dude... he may not be from an English speaking country and using a translator or what little knowledge they have to type in English... there are people like that on this site... and when have you known a translator to translate text in grammatically correct English... be a little more understanding.

## denniskhor -4

Sorry dude, i knw my english poor enough, i tried to explain again, hope u guys understand,

My question:

If my text file name inconsistent only for a part. Such as "123 Main Page.txt", but maybe will be "124 Main Page.txt", the number in front will different based on counter, so i wan use endswith Main Page.txt to search "123 Main Page.txt" or "124 Main Page.txt" in the "C:\text folder", so the output can print out "C:\text folder\123 Main Page.txt" or "C:\text folder\124 Main Page.txt" once found.

## woooee 814

so i wan(t to) use endswith Main Page.txt to search

Post the code that reads the directory and your usage of endswith. I don't see a problem here, i.e. read the directory and go through the list to see if the file name ends with whatever.

## Arrorn -4

That is want he wants to find out how to do....:idea:

## denniskhor -4

path = 'C:/Image Folder'
extension = 'text page.txt'

def printFiles(dirList,spaceCount,typeList):
for file in dirList:
for ext in typeList:
if file.endswith(ext):
print '/'.rjust(spaceCount+1)+file
break

def printDirectory(dirEntry,typeList):
print dirEntry[0]+'/'
printFiles(dirEntry[2],len(dirEntry[0]),typeList)

extList = []
for ext in extension:
extList.append(extension)

for directory in os.walk(path):
printDirectory(directory,extList)

The output will be

>>> C:/Image Folder/
/[2009'07'13 @ 10'58'19] text page.txt
>>>

But i want the out put is X = "C:/Image Folder/[2009'07'13 @ 10'58'19] text page.txt", then i can use the X.

## woooee 814

In addition to/instead of printing the file name, send the file name to another function at that point and that function can do whatever you want with that file.

## woooee 814

Duplicate post removed.

## denniskhor -4

def printDirectory(dirEntry,typeList):
for ext in extension:
extList.append(extension)
for directory in os.walk(path):
for file in dirEntry[2]:
for ext in typeList:
if file.endswith(ext):
print dirEntry[0]+'/'+file
break

for directory in os.walk(path):
printDirectory(directory,extList)

I changed it like tat, but i wan use the output "C:/Image Folder/[2009'07'13 @ 10'58'19] text page.txt" on other place... how i get it? If my question confusing, please let me know and i m still new in Python. Thanks.