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

Friday 24 January 2020

BASIC FUNCTIONS PYTHON

import os
import fnmatch

print("=============================================")

print("              PERFORMING BASIC FUNCTIONS OF OS MODULE                         ")

z=os.getcwd()

"""
os.mkdir(os.path.join(z,"NEW"))

os.rmdir('/home/jitender/PYTHON_SCRIPTS/BLOG/NEW')
"""
for i,j,k in os.walk('/home/jitender/PYTHON_SCRIPTS/'):
for n in k:
if fnmatch.fnmatch(n,'*.gz'):
print("Removing %s" %n)
os.remove(os.path.join(i,n))

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management