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))

Sunday, 14 December 2014

Reverse 3 Digit number

#include<iostream>
#include<conio.h>
using namespace std;
int fun(int n)
{
int sum=0;  
if(n==0)
return 1 ;
return (n*fun(n-1));
}

int main()
{
int z,k,sum=0;
int x=234;
int t=100;
int p=1;
int no=0;
int d=3;
while(d)
{
z=x/t;
x=x%t;
no=no+z*p;
p=p*10;
t=t/10;
d=d-1;
}
cout<<no;
return 0;
}

Sunday, 14 September 2014

Insertion Deletion In Linked List

#include<iostream>
#include<conio.h>
using namespace std;
struct link
{
int data;
struct link *next;

};

void display();
void initial();
void deletion();

struct link *newn,*loc,*start=NULL,*ptr;


int main()
{
int i,item;
for(i=1;i<5;i++)
    {
    cout<<"Enter element";
cin>>item;
newn =new struct link[1];
newn->data=item;
newn->next=NULL;


if(start==NULL)
    {
    start=newn;
    }
    else
    {
    ptr=start;
    while(ptr->next!=NULL)
    {
    ptr=ptr->next;
   
    }
   
    ptr->next=newn;
    }

 }
   
    display();
    //for(i=1;i<=2;i++)
    //{
   
initial();
//}
}





void display()
{
ptr=start;
while(ptr!=NULL)
{
cout<<ptr->data;
cout<<"-->";
ptr=ptr->next;
}


}



void initial()
{
int item;
    cout<<"Enter the item which u want to insert in begining";
    cin>>item;
   
    struct link *p;
    p=new struct link[1];
    p->data=item;
    p->next=NULL;
    if(start==NULL)
    {
    start=p;
   
    }
else
    {
      p->next=start;
 start=p;
    }

display();
deletion();
}


void deletion()
{
char c;
cout<<"do u want to delete from begining";
cin>>c;
if(c=='y')
{
start=start->next;
display();
}

}
 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management