使用python将文件放在文件夹中

使用python将文件放在文件夹中,python,Python,我在线抓取了这个文件拆分器,但我需要将文件块放在指定的文件夹中。代码是: #define inputs file = raw_input('enter file location:') output = raw_input('enter file output location:') chunk_size = raw_input('choose output chunk size(in bytes):') # define the function to split the file into

我在线抓取了这个文件拆分器,但我需要将文件块放在指定的文件夹中。代码是:

#define inputs
file = raw_input('enter file location:')
output = raw_input('enter file output location:')
chunk_size = raw_input('choose output chunk size(in bytes):')
# define the function to split the file into smaller chunks
def splitFile(inputFile,chunkSize):
    #read the contents of the file
    f = open(inputFile, 'rb')
    data = f.read()
    f.close()
# get the length of data, ie size of the input file in bytes
    bytes = len(data)
#calculate the number of chunks to be created
    noOfChunks= bytes/chunkSize
    if(bytes%chunkSize):
        noOfChunks+=1
#create a info.txt file for writing metadata
    f = open('info.txt', 'w')
    f.write(inputFile+','+'chunk,'+str(noOfChunks)+','+str(chunkSize))
    f.close()
    chunkNames = []
    for i in range(0, bytes+1, chunkSize):
        fn1 = "chunk%s" % i
        chunkNames.append(fn1)
        f = open(fn1, 'wb')
        f.write(data[i:i+ chunkSize])
        f.close()
#split file into chunks
splitFile(file,chunk_size)
#move chunks to output
因此,我确信您可以看到,我已经制作了文件拆分器,我只需要将文件块放在“output”变量的目录中。
有人能帮帮我吗

正在此行中创建新文件:

f = open(fn1, 'wb')
fn1 = "chunk%s" % i
它使用在此行中创建的名称:

f = open(fn1, 'wb')
fn1 = "chunk%s" % i
这表明,如果您想要包含目录,您可以使用以下内容:

fn1 = "output/chunk%s" % i

为什么不在编写块时将它们写回输出文件夹?我认为问题在于,他/她不理解复制的代码在做什么,所以他看不到在哪里/如何修改它。它是复制的,但我计划制作自己的版本。复制它的原因是因为我试着四处询问,有人向我展示了实际的功能,而不是解释如何编写文件拆分器。我知道它是如何工作的,但一旦它被“创建一个info.txt文件来编写元数据”弄糊涂了,因为我还不太熟悉pythons文件操作,但我还在学习。