Python Assignment & Project #1
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Write a python program which should following
- Prompt Input from user one Location of Linux filesystem and list each files of the directory.
- file name must be listed with row and serical num ie. 1.2.3.4.5 along with size | owner | last modified date.
- User must be promoted with a options to delete files by choosing serical num ie. 1.2.3.4.5
- User must be promoted every time with 2 options. 1. Exit the interactive session 2. Continue with file delete ops.
import os
listofiledict={}
directoryName=""
path=""
def showfiles():
directoryName=input("Enter your directory name with full path")
#print(os.system(('ls %s -l')% directoryName))
listFiles=os.listdir(directoryName)
i=1;
for f in listFiles:
path=directoryName + "/" + f
#print(i,os.system(('ls -l %s')% '"'+path+'"'))
listofiledict[i]=path
i+=1
def delfileaction():
delyes=input("Do you want to delte file Enter yes or no ")
if(delyes == "yes" or delyes == "y"):
delfileNum=input("Enter the seq number to delete the file")
delfile(delfileNum)
if(delyes == "no" or delyes == "n"):
exit()
def choosefuncrtion():
action=input("Enter your action: showlist or delete")
print(action)
if(action == "showlist"):
showfiles()
if(action == "delete"):
showfiles()
delfileaction()
def delfile(delfileNum):
print(listofiledict)
filestodel=listofiledict[int(delfileNum)]
delaction=os.system(('rm %s -f')% filestodel)
delyes=input("Do you want to delte more file Enter yes or no")
if(delyes == "yes" or delyes == "y"):
delfileNum=input("Enter the seq number to delete the file")
delfile(delfileNum)
if(delyes == "no" or delyes == "n"):
exit()
choosefuncrtion()