Write A Program in Python For USB Device File Management. Check Usefulness of Command e2fsck For Different File Systems Mounted on Computer. | I'M FROSTY

HTML Image

IMFROSTY

Whats Hot ?

This Domain Name is for Sale !! Please contact Admin : pandyanhardik@gmail.com, If you are interested to buy it..

Write A Program in Python For USB Device File Management. Check Usefulness of Command e2fsck For Different File Systems Mounted on Computer.

 =========  Python Program ==========

import os
import sys
import shutil

def ls():
print"The files present in your usb device are... \n"
os.system("ls -l /root/usbmnt1");
def mkdir():
ch=raw_input("Make a directory or file (d/f) :")
if(ch=='f'):
name=raw_input("Enter the name of the file :");
path="/root/usbmnt1/"+name;
fopen=open(path,'w');
fopen.close();
print "File successfully created!";

if(ch=='d'):
name=raw_input("Enter the name of the Directory :");
path="/root/usbmnt1/"+name;
os.mkdir(path,1777);
print "Directory successfully created!";
def delete():
ch=raw_input("Delete directory or file (d/f) :")
 
if(ch=='d'):
name=raw_input("Enter the name of the directory :");
path="/root/usbmnt1/"+name;
os.rmdir(path);
print "Directory successfully Removed!";
 
if(ch=='f'):
name=raw_input("Enter the name of the file:");
path="/root/usbmnt1/"+name;
fdel="rm "+path
os.system(fdel);
print "File successfully Removed!";
def copy():
path=raw_input("Enter the path of source file :");
tar=raw_input("Enter the target destination path :");
shutil.copy(path,tar);
print "File successfully copied!";

def rename():
name=raw_input("Enter the name of the file :");
path="/root/usbmnt1/"+name;
newname=raw_input("Enter the new name of the file :");
newpath="/root/usbmnt1/"+newname;    
cmd="mv -f "+path+" "+newpath
os.system(cmd);
print "Directory successfully Renamed!";
def mod():

name=raw_input("Enter the name of the file :");

path="/root/usbmnt1/"+name;
cmd="gedit "+path+"&"
os.system(cmd);
print"File modification successfull!"
def disp():
name=raw_input("Enter the name of the file :");
path="/root/usbmnt1/"+name;
cmd="cat "+path
os.system(cmd); 

def main():
os.system("umount /dev/sdb1");
if(os.path.exists("/root/usbmnt1")==0):
os.system("mkdir -m 777 /root/usbmnt1 ");
ret=os.system("mount -t auto /dev/sdb1 /root/usbmnt1");
if(ret!=0):
sys.exit(0);
print "Usb device has been mounted successfully!"

options={
'1':ls,
'2':mkdir,
'3':delete,
'4':copy,
'5':rename,
'6':mod,
'7':disp
}

while(True):
print "\n1.List the files in USB\n2.Make \n3.Delete \n4.Copy files\n
5.Rename a file.\n6.Modify file content.\n7.Display file content.\n8.Exit";
ch=raw_input("\n \t Enter your choice :");
if(ch=='8'):
break;
options[ch]();

if __name__=='__main__':

main();


#Pls note.
#The source device is by default /dev/sdb1.
#If mount fails, check fdisk -l To see if usb device is in another partition(eg. sda1 or sdc1) and make necessary change in mount command of the #code.!


============ OUTPUT ============

 [root@localhost ~]# python usb.py

Usb device has been mounted successfully!

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :1

The files present in your usb device are...

total 168

-rwxr-xr-x. 1 root root     0 Sep 17 11:47 abc
-rwxr-xr-x. 1 root root    67 May  6  2013 autorun.inf
drwxr-xr-x. 3 root root  4096 Apr 23  2013 boot
drwxr-xr-x. 2 root root  4096 May  8  2013 casper
drwxr-xr-x. 3 root root  4096 Apr 23  2013 dists
drwxr-xr-x. 3 root root  4096 Apr 23  2013 EFI
drwxr-xr-x. 2 root root  4096 Apr 23  2013 install
drwxr-xr-x. 2 root root  8192 Apr 23  2013 isolinux
-rwxr-xr-x. 1 root root 18092 Apr  5  2012 license.txt
-rwxr-xr-x. 1 root root 19678 May  8  2013 md5sum.txt
-rwxr-xr-x. 1 root root     0 Sep 17 12:26 myfile
-rwxr-xr-x. 1 root root     0 Sep 17 12:12 myfile.txt
-rwxr-xr-x. 1 root root    16 Sep 17 12:31 newfile
-rwxr-xr-x. 1 root root     0 Sep 17 12:30 newfile~
drwxr-xr-x. 2 root root  4096 Apr 23  2013 pics
drwxr-xr-x. 6 root root  4096 Apr 23  2013 pool
drwxr-xr-x. 2 root root  4096 Apr 23  2013 preseed
-rwxr-xr-x. 1 root root   230 Apr 23  2013 README.diskdefines
drwxr-xr-x. 2 root root  4096 Sep 16 17:07 System Volume Information
-rwxr-xr-x. 1 root root     0 May  6  2013 ubuntu
-rwxr-xr-x. 1 root root 49070 Jan 16  2014 Uni-USB-Installer-Copying.txt
-rwxr-xr-x. 1 root root 18597 Jun 30 22:10 Uni-USB-Installer-Readme.txt
drwxr-xr-x. 2 root root  4096 Sep 17 12:13 uui

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :2
Make a directory or file (d/f) :f
Enter the name of the file :vivek
File successfully created!

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :1

The files present in your usb device are...

total 168

-rwxr-xr-x. 1 root root     0 Sep 17 11:47 abc
-rwxr-xr-x. 1 root root    67 May  6  2013 autorun.inf
drwxr-xr-x. 3 root root  4096 Apr 23  2013 boot
drwxr-xr-x. 2 root root  4096 May  8  2013 casper
drwxr-xr-x. 3 root root  4096 Apr 23  2013 dists
drwxr-xr-x. 3 root root  4096 Apr 23  2013 EFI
drwxr-xr-x. 2 root root  4096 Apr 23  2013 install
drwxr-xr-x. 2 root root  8192 Apr 23  2013 isolinux
-rwxr-xr-x. 1 root root 18092 Apr  5  2012 license.txt
-rwxr-xr-x. 1 root root 19678 May  8  2013 md5sum.txt
-rwxr-xr-x. 1 root root     0 Sep 17 12:26 myfile
-rwxr-xr-x. 1 root root     0 Sep 17 12:12 myfile.txt
-rwxr-xr-x. 1 root root    16 Sep 17 12:31 newfile
-rwxr-xr-x. 1 root root     0 Sep 17 12:30 newfile~
drwxr-xr-x. 2 root root  4096 Apr 23  2013 pics
drwxr-xr-x. 6 root root  4096 Apr 23  2013 pool
drwxr-xr-x. 2 root root  4096 Apr 23  2013 preseed
-rwxr-xr-x. 1 root root   230 Apr 23  2013 README.diskdefines
drwxr-xr-x. 2 root root  4096 Sep 16 17:07 System Volume Information
-rwxr-xr-x. 1 root root     0 May  6  2013 ubuntu
-rwxr-xr-x. 1 root root 49070 Jan 16  2014 Uni-USB-Installer-Copying.txt
-rwxr-xr-x. 1 root root 18597 Jun 30 22:10 Uni-USB-Installer-Readme.txt
drwxr-xr-x. 2 root root  4096 Sep 17 12:13 uui
-rwxr-xr-x. 1 root root     0 Sep 17 20:52 vivek

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :5

Enter the name of the file :vivek

Enter the new name of the file :vivekcomp

Directory successfully Renamed!

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :1

The files present in your usb device are...

total 168

-rwxr-xr-x. 1 root root     0 Sep 17 11:47 abc
-rwxr-xr-x. 1 root root    67 May  6  2013 autorun.inf
drwxr-xr-x. 3 root root  4096 Apr 23  2013 boot
drwxr-xr-x. 2 root root  4096 May  8  2013 casper
drwxr-xr-x. 3 root root  4096 Apr 23  2013 dists
drwxr-xr-x. 3 root root  4096 Apr 23  2013 EFI
drwxr-xr-x. 2 root root  4096 Apr 23  2013 install
drwxr-xr-x. 2 root root  8192 Apr 23  2013 isolinux
-rwxr-xr-x. 1 root root 18092 Apr  5  2012 license.txt
-rwxr-xr-x. 1 root root 19678 May  8  2013 md5sum.txt
-rwxr-xr-x. 1 root root     0 Sep 17 12:26 myfile
-rwxr-xr-x. 1 root root     0 Sep 17 12:12 myfile.txt
-rwxr-xr-x. 1 root root    16 Sep 17 12:31 newfile
-rwxr-xr-x. 1 root root     0 Sep 17 12:30 newfile~
drwxr-xr-x. 2 root root  4096 Apr 23  2013 pics
drwxr-xr-x. 6 root root  4096 Apr 23  2013 pool
drwxr-xr-x. 2 root root  4096 Apr 23  2013 preseed
-rwxr-xr-x. 1 root root   230 Apr 23  2013 README.diskdefines
drwxr-xr-x. 2 root root  4096 Sep 16 17:07 System Volume Information
-rwxr-xr-x. 1 root root     0 May  6  2013 ubuntu
-rwxr-xr-x. 1 root root 49070 Jan 16  2014 Uni-USB-Installer-Copying.txt
-rwxr-xr-x. 1 root root 18597 Jun 30 22:10 Uni-USB-Installer-Readme.txt
drwxr-xr-x. 2 root root  4096 Sep 17 12:13 uui
-rwxr-xr-x. 1 root root     0 Sep 17 20:52 vivekcomp

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :7

Enter the name of the file :newfile

My file is here

1.List the files in USB
2.Make
3.Delete
4.Copy files
5.Rename a file.
6.Modify file content.
7.Display file content.
8.Exit

Enter your choice :8
=================================================================
# Share It With Your Cool Friends to Help Them!!
Write A Program in Python For USB Device File Management. Check Usefulness of Command e2fsck For Different File Systems Mounted on Computer. Reviewed by Hardik Pandya on 3:38:00 PM Rating: 5

No comments:

All Rights Reserved by I'M FROSTY © 2014 - 2017
*The Content Is Copyrighted To & May Not Be Copied / Republished.

Biểu mẫu liên hệ

Name

Email *

Message *

Powered by Blogger.