Question: Someone please look over my code for my hw assignment. I'm having trouble trying to make it closely follow the psuedocode. It's making errors as

Someone please look over my code for my hw assignment. I'm having trouble trying to make it closely follow the psuedocode. It's making errors as well, it makes the folders but does not place the images within them.

The script should read an index file, create a new folder for each album, then rename and copy the image files into the album folders and it needs to add print statements in the script to tell the tell the user what the script is doing. Need to arrange into three albums at least. IN PYTHON

Here's the psuedocode the professor provided:

import os

from shutil import copyfile

def CopySrcDst(data):

previous_folder, counter="",0

for line in data:

folder_name = line[0]

file_name = line[1]

if previous_folder!=folder_name:

os.mkdir(folder_name)

previous_folder = folder_name

counter=1

new_photo_name = folder_name + str(counter) + file_name

copyfile(file_name, new_photo_name)

counter+=1

def main(index_file):

#index file contains formatted text like [folder-name pic_name] on each lines

data=[]

with open(index_file) as fin:

lines = fin.readlines()

data = list(map(lambda l: l.strip().split(" "),lines))

CopySrcDst(data)

main("index.txt")

and here's my code

import os

from shutil import copyfile

def CopySrcDst(data):

previous_folder, counter="",0

for line in data:

folder_name = line[0]

file_name = line[1]

if previous_folder!=folder_name:

os.mkdir(folder_name)

previous_folder = folder_name

counter=1

new_photo_name = folder_name + str(counter) + file_name

copyfile(file_name, new_photo_name)

counter+=1

def main(index_file):

data=[]

with open(index_file) as fin:

lines = fin.readlines()

data = list(map(lambda l: l.strip().split(" "),lines))

CopySrcDst(data)

main("index.txt")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!