September 3rd, 2013, 01:46 AM
Copying path from command prompt
I got a scenario where I have to copy the path name to a argument or variable (eg: D:\dev\python\file.py) of a file directory from command prompt only. Lets say python folder has 50 or more python files. I want to delete the files which has "virus" word in those 50 python files. from the python folder.
How can i work on this can anyone please help me !!
September 3rd, 2013, 05:12 AM
The 'glob' module is the easiest to pull in files by name with wildcard matching:
Or use os.listdir() to get all files (but you have to add the base path to the result yourself):
>>> import glob
['c:\\python27\\python.exe', 'c:\\python27\\pythonw.exe', 'c:\\python27\\Removepywin32.exe']
Use os.remove() to delete files.
mypath = 'c:\\python27'
for f in os.listdir(mypath):
print os.path.join(mypath, f)
Also, see: http://stackoverflow.com/questions/120656/directory-listing-in-python