def read_folder_recursive(folderpath):
    entries = os.listdir(folderpath)
    for entry in entries:
        if os.listdir(entry):
            read_folder_recursive(entry)
        else:
            lst.append(entry)
    myList.write_list_to_file('b_assignment.csv', lst)
def read_folder_recursive(folderpath):
    entries = os.listdir(folderpath)
    for entry in entries:
        if os.path.isdir(entry):
            read_folder_recursive(entry)
        else:
            lst.append(entry)

    myList.write_list_to_file(argv[2], lst)
예제 #3
0
def make_down(*files):
    for file in files:
        for ele in file:
            with open(ele) as f_obj:
                content = f_obj.readlines()
            for line in content:
                if '#' in line:
                    lst.append(line.strip(','))
    myList.write_list_to_file('test.csv', lst)
예제 #4
0
import os.path
from os import path
from sys import argv
import python_second_assignment as myList

# A. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"


def read_folder():
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)


myList.write_list_to_file(entries, argv[2])
def read_folder(foldername, filename):
    myList.write_list_to_file(filename, os.listdir())
예제 #6
0
def write_filenames_to_file(folderpath):
    entries = os.listdir(folderpath)
    myList.write_list_to_file('b_assignment.csv', entries)
def write_filenames_to_file(folderpath):
    entries = os.listdir(folderpath)
    myList.write_list_to_file(entries)
예제 #8
0
import os.path
from os import path
from sys import argv
import python_second_assignment as myList

# A. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"


def read_folder():
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)


myList.write_list_to_file(argv[2])
예제 #9
0
def read_folder(foldername, filename):
    lst = os.listdir()
    myList.write_list_to_file(filename, os.listdir())
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)
예제 #10
0
import os.path
from os import path
from sys import argv
import python_second_assignment as myList

# A. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"


def read_folder():
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)


myList.write_list_to_file(folderpath, argv[2])
예제 #11
0
import os.path
from os import path
from sys import argv
import python_second_assignment as myList

# A. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"
def read_folder():
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)
read_folder()

myList.write_list_to_file(read_folder, argv[2])
예제 #12
0
import os.path
from os import path
from sys import argv
import python_second_assignment as myList

# A. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"


def read_folder():
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)


myList.write_list_to_file()
import os.path
from os import path
from sys import argv
import python_second_assignment as myList

# A. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"


def read_folder():
    entries = os.listdir(folderpath)
    for entry in entries:
        print(entry)


read_folder()

myList.write_list_to_file(read_folder)
예제 #14
0
import os.path
from os import path
from sys import argv
import argparse

import python_second_assignment as myList

# 1. first function takes a path to a folder and writes all filenames in the folder to a specified output file
folderpath = "/Users/robin/Desktop/semester_4/python/myPythonCode/week 2"
def write_filenames_to_file(folderpath)
    entries = os.listdir(folderpath)
    myList.write_list_to_file(folderpath)

#2.second takes a path to a folder and write all filenames recursively (files of all sub folders to)
lst=[]
def read_folder_recursive(folderpath):
    entries = os.listdir(folderpath)
    for entry in entries:
        if os.path.isdir(entry):
            read_folder_recursive(entry)
        else:
            lst.append(entry)

    myList.write_list_to_file('b_assignment.csv', lst)

read_folder_recursive(argv[1])

# 3. third takes a list of filenames and print the first line of each
def read_first_line_from_files(*files):
    for file in files:
        for ele in file:
예제 #15
0
                content = f_obj.readline()
            for line in content:
                if '@' in content:
                    print(line)

#fifth takes a list of md files and writes all headlines (lines starting with #) to a file
# Make sure your module can be called both from cli and imported to another module Create a new module that imports utils.py and test each function.
def make_down(*files)
    for file in files:
        for ele in file:
            with open(ele) as f_obj:
                content = f_obj.readlines()
            for line in content:
                if '#' in line:
                    lst.append(line.strip(','))
    myList.write_list_to_file('test.csv', lst)
def run():

    if args.exercise1:
        folderpath = argv[2]
        write_filenames_to_file(folderpath)
    if args.exercise2:
        folderpath = argv[2]
        read_folder_recursive(folderpath)
    if args.exercise3:
        folderpath = argv[2:]
        read_first_line_from_files(folderpath)
    if args.exercise4:
        folderpath = argv[2]
        read_if_at(folderpath)