i need to parse through a list of files in a folder and separate only those files with a particular extension such as doc or htm files. anyone has any idea how to write a python script for this?
: i need to parse through a list of files in a folder and separate only those files with a particular extension such as doc or htm files. anyone has any idea how to write a python script for this? :
[code] import glob location = "./" #path where you search particularext = glob.glob(location + '*.doc') particularext.extend(glob.glob(location + '*.htm')) [/code]
thanks drost glob seems to specific to Unix , i tried this in my NT m/c it doesnt give any results, although no errors are thrown, can u pl try this?:
i tried this : import glob location="C: sm_imagesTSM_BA_Client" particularext=glob.glob(location+'*.txt') particularext.extend(glob.glob(location+'*.html')) i doesnt give any results for any folder or any existing file extension.
: i need to parse through a list of files in a folder and separate only those files with a particular extension such as doc or htm files. anyone has any idea how to write a python script for this? : : : : [code] : import glob : location = "./" #path where you search : particularext = glob.glob(location + '*.doc') : particularext.extend(glob.glob(location + '*.htm')) : [/code] : : Here you'll get a list of those filenames. : : Drost : :
[b][red]This message was edited by Drost at 2004-9-10 3:18:57[/red][/b][hr] : : thanks drost : glob seems to specific to Unix , i tried this in my NT m/c it doesnt give any results, although no errors are thrown, can u pl try this?: : : i tried this : : import glob : location="C: sm_imagesTSM_BA_Client" : particularext=glob.glob(location+'*.txt') : particularext.extend(glob.glob(location+'*.html')) : i doesnt give any results for any folder or any existing file extension. :
Glob works on windows but be aware that to use pathstrings on windows you need to use either raw strings or double your slashes so that you don't trigger the escape character meaning of single slashes ( means tab, etc.)... So your location should be like
[code] location = r"C: sm_imagesTSM_BA_Client" -----------! or
hi drost, thanks once again for the suggestion i once again tried your suggestion like this :looking for two text files created in C:\Documents and Settings
import glob location= "C:\Documents and Settings" particularext=glob.glob(location+r'*.txt') particularext.extend(glob.glob(location+r'*.html'))
the run doesnt give me any results ? does it have any other missing element? thanks somuch for your patience , som
[b][red]This message was edited by Drost at 2004-9-10 3:18:57[/red][/b][hr] : : : : thanks drost : : glob seems to specific to Unix , i tried this in my NT m/c it doesnt give any results, although no errors are thrown, can u pl try this?: : : : : i tried this : : : import glob : : location="C: sm_imagesTSM_BA_Client" : : particularext=glob.glob(location+'*.txt') : : particularext.extend(glob.glob(location+'*.html')) : : i doesnt give any results for any folder or any existing file extension. : : : : Glob works on windows but be aware that to use pathstrings on windows you need to use either raw strings or double your slashes so that you don't trigger the escape character meaning of single slashes ( means tab, etc.)... : So your location should be like : : [code] : location = r"C: sm_imagesTSM_BA_Client" : -----------! : or : : location = "C:\tsm_images\TSM_BA_Client" : --------------!-----------! : [/code] : : But then the rest needs the following correction (my fault). Strings don't like odd number of slashes at the end... : : [code] : particularext=glob.glob(location + r'*.txt') : particularext.extend(glob.glob(location + r'*.html') : [/code] : : Drost : : :
[b][red]This message was edited by Drost at 2004-9-22 4:7:51[/red][/b][hr] : hi drost, : thanks once again for the suggestion : i once again tried your suggestion like this :looking for two text files created in C:\Documents and Settings : : import glob : location= "C:\Documents and Settings" : particularext=glob.glob(location+r'*.txt') : particularext.extend(glob.glob(location+r'*.html')) : : the run doesnt give me any results ? does it have any other missing element? : thanks somuch for your patience , : som
Sorry for the late answer. Funnily that code works for me...
[code] import glob location= "C:\Documents and Settings" particularext=glob.glob(location+r'*.txt') particularext.extend(glob.glob(location+r'*.html')) raw_input(particularext) #this waits for an Enter after printing the result [/code]
Do such files really exist in that directory? You probably have had reading rights too if you were able to create those files in the first place.
So you say it produced only an empty list in the end?
Comments
:
[code]
import glob
location = "./" #path where you search
particularext = glob.glob(location + '*.doc')
particularext.extend(glob.glob(location + '*.htm'))
[/code]
Here you'll get a list of those filenames.
Drost
thanks drost
glob seems to specific to Unix , i tried this in my NT m/c it doesnt give any results, although no errors are thrown, can u pl try this?:
i tried this :
import glob
location="C: sm_imagesTSM_BA_Client"
particularext=glob.glob(location+'*.txt')
particularext.extend(glob.glob(location+'*.html'))
i doesnt give any results for any folder or any existing file extension.
: i need to parse through a list of files in a folder and separate only those files with a particular extension such as doc or htm files. anyone has any idea how to write a python script for this?
: :
:
: [code]
: import glob
: location = "./" #path where you search
: particularext = glob.glob(location + '*.doc')
: particularext.extend(glob.glob(location + '*.htm'))
: [/code]
:
: Here you'll get a list of those filenames.
:
: Drost
:
:
:
: thanks drost
: glob seems to specific to Unix , i tried this in my NT m/c it doesnt give any results, although no errors are thrown, can u pl try this?:
:
: i tried this :
: import glob
: location="C: sm_imagesTSM_BA_Client"
: particularext=glob.glob(location+'*.txt')
: particularext.extend(glob.glob(location+'*.html'))
: i doesnt give any results for any folder or any existing file extension.
:
Glob works on windows but be aware that to use pathstrings on windows you need to use either raw strings or double your slashes so that you don't trigger the escape character meaning of single slashes ( means tab, etc.)...
So your location should be like
[code]
location = r"C: sm_imagesTSM_BA_Client"
-----------!
or
location = "C:\tsm_images\TSM_BA_Client"
--------------!-----------!
[/code]
But then the rest needs the following correction (my fault). Strings don't like odd number of slashes at the end...
[code]
particularext=glob.glob(location + r'*.txt')
particularext.extend(glob.glob(location + r'*.html')
[/code]
Drost
thanks once again for the suggestion
i once again tried your suggestion like this :looking for two text files created in C:\Documents and Settings
import glob
location= "C:\Documents and Settings"
particularext=glob.glob(location+r'*.txt')
particularext.extend(glob.glob(location+r'*.html'))
the run doesnt give me any results ? does it have any other missing element?
thanks somuch for your patience ,
som
[b][red]This message was edited by Drost at 2004-9-10 3:18:57[/red][/b][hr]
: :
: : thanks drost
: : glob seems to specific to Unix , i tried this in my NT m/c it doesnt give any results, although no errors are thrown, can u pl try this?:
: :
: : i tried this :
: : import glob
: : location="C: sm_imagesTSM_BA_Client"
: : particularext=glob.glob(location+'*.txt')
: : particularext.extend(glob.glob(location+'*.html'))
: : i doesnt give any results for any folder or any existing file extension.
: :
:
: Glob works on windows but be aware that to use pathstrings on windows you need to use either raw strings or double your slashes so that you don't trigger the escape character meaning of single slashes ( means tab, etc.)...
: So your location should be like
:
: [code]
: location = r"C: sm_imagesTSM_BA_Client"
: -----------!
: or
:
: location = "C:\tsm_images\TSM_BA_Client"
: --------------!-----------!
: [/code]
:
: But then the rest needs the following correction (my fault). Strings don't like odd number of slashes at the end...
:
: [code]
: particularext=glob.glob(location + r'*.txt')
: particularext.extend(glob.glob(location + r'*.html')
: [/code]
:
: Drost
:
:
:
: hi drost,
: thanks once again for the suggestion
: i once again tried your suggestion like this :looking for two text files created in C:\Documents and Settings
:
: import glob
: location= "C:\Documents and Settings"
: particularext=glob.glob(location+r'*.txt')
: particularext.extend(glob.glob(location+r'*.html'))
:
: the run doesnt give me any results ? does it have any other missing element?
: thanks somuch for your patience ,
: som
Sorry for the late answer.
Funnily that code works for me...
[code]
import glob
location= "C:\Documents and Settings"
particularext=glob.glob(location+r'*.txt')
particularext.extend(glob.glob(location+r'*.html'))
raw_input(particularext) #this waits for an Enter after printing the result
[/code]
Do such files really exist in that directory?
You probably have had reading rights too if you were able to create those files in the first place.
So you say it produced only an empty list in the end?
Drost