January 5th, 2005, 03:18 PM
Search for files (python)
Can anyone please help me with some source code to search for .txt files in current dir and save the result to a variable like 'txtFound' if you dont understand ill give you a batch example(Hope ya know batch )
FOR %%B IN (*.txt) DO SET txtFound=%%B
Ok thats a nice example
January 5th, 2005, 03:37 PM
I dont know batch, but this works...
>>> import glob
['dummy.txt', 'message.txt', 'optLog.txt', 'README.txt', 'result.txt', 'X_2_trn.txt', 'X_2_tst.txt', 'X_2_val.txt', 'Y_2_trn.txt', 'Y_2_val.txt']
It returns a list of all the files in the current directory matching the pattern specified. You can enter a path as well..
Hope this helps.
January 5th, 2005, 07:33 PM
January 5th, 2005, 07:57 PM
Originally Posted by Zone
this code can runs in Windows ??
as i know, "glob" is only works in UNIX. can anyone confirm with me about it?
January 5th, 2005, 08:02 PM
The glob module works on Unix and Windows. The module docs will tell you about any restrictions.