Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Module 要在文件夹和子文件夹中运行的模块_Module_Directory Structure - Fatal编程技术网

Module 要在文件夹和子文件夹中运行的模块

Module 要在文件夹和子文件夹中运行的模块,module,directory-structure,Module,Directory Structure,该程序在current目录中查找以“Oddball_”开头并以“.csv”结尾的文件,然后根据文件名通过编号为1到4的模块运行这些文件 这适用于根目录中的文件,但是在文件夹和子文件夹中进一步导航时会产生错误 计算_results.py sort_run1.py:sort_run2.py/sort_run3.py/sort_run4.py都是相似的 预期的输出是遍历文件夹中的所有文件。在我的sort\u run1.py文件中,我 df=pd.read\u csv(文件名) 但我们需要以下几点 df

该程序在current目录中查找以“Oddball_”开头并以“.csv”结尾的文件,然后根据文件名通过编号为1到4的模块运行这些文件

这适用于根目录中的文件,但是在文件夹和子文件夹中进一步导航时会产生错误

计算_results.py sort_run1.py:sort_run2.py/sort_run3.py/sort_run4.py都是相似的
预期的输出是遍历文件夹中的所有文件。

在我的sort\u run1.py文件中,我

df=pd.read\u csv(文件名)

但我们需要以下几点

df=pd.read\u csv(f'./{dir\u name}/{filename}')

import sort_run1
import sort_run2
import sort_run3
import sort_run4

# Import the os module, for the os.walk function
import os

# Set the directory you want to start from
rootDir = '.'
for dirName, subdirList, fileList in os.walk(rootDir):
    for filename in fileList:
        if filename.startswith('Oddball_') and filename.endswith('.csv'):
            if dirName not in fileList:
                print('directory location: ' + dirName)
                if filename.startswith('Oddball_1'):
                    sort_run1.sort1(filename)
                elif filename.startswith('Oddball_2'):
                    sort_run2.sort2(filename)
                elif filename.startswith('Oddball_3'):
                    sort_run3.sort3(filename)
                elif filename.startswith('Oddball_4'):
                    sort_run4.sort4(filename)
                else:
                    continue
        else:
            continue
import pandas as pd
import pathlib

def sort1(pid):
    print(pid)
    # Name of file to read
    filename = pid
        
    # data frame to create from file
    df = pd.read_csv(filename)
    
##
##I've removed all the stuff that happens here to minimize code
##