Social Icons

Thursday, 30 January 2020

Checking & Removing Files with matching extensions


import os
import gzip
import fnmatch
import tarfile

for i,k,l in os.walk("/home/jitender/PYTHON_SCRIPTS"):
for nn in l:
x=os.path.join(i,nn)
if fnmatch.fnmatch(x,'*.gz'):
print("Removing file %s" %x)
os.remove(x)


x=int(raw_input("Enter any name"))

print(x)


for i in range(1,10):
print(i),
print()
if (os.path.exists("/home/jitender/PYTHON_SCRIPTS/new1.tar") == False ):
print("Path not exists")
elif (os.path.isdir("/home/jitender/PYTHON_SCRIPTS/new1.tar") == True ):
print("It is directory Path")
elif (os.path.isfile("/home/jitender/PYTHON_SCRIPTS/new1.tar") == True ):
print("It is file")
else:
print("Nothing")


OUTPUT:

[root@localhost PYTHON_SCRIPTS]# python new.py
Enter any name3
3
1 2 3 4 5 6 7 8 9 ()
It is file

No comments:

Post a Comment

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management