Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions