0
入力ファイルのデータを使用して各フォルダ内にディレクトリとファイルを作成しようとしています。Python mkdirの問題、ファイルが存在しないというエラー
これは、最初の1のために動作しますが、その後、私は任意の助けをいただければ幸い、今ちょうど時間この見つめてそれを得るように見えることはできませんされている私にFileExistsError
を与えます。
ファイルのデータは、この
>unique id
string of unknown length
のように見え、私が試したコードは、この
import os
# find a character
CharLocArray = []
NewLineArray = []
with open('/home/tjbutler/software/I-TASSER5.0/seqdata/Egg_protein/seq.fasta', 'r') as myfile:
data = myfile.read()
GreaterThan = '>'
NewLine = '\n'
# code to read char into var
# myfile.read().index('>')
index = 0
while index < len(data):
index = data.find('>', index)
CharLocArray.append(index)
if index == -1:
break
index += 2
index2 = 0
while index2 < len(data):
index2 = data.find('\n', index2)
NewLineArray.append(index2)
if index2 == -1:
break
index2 += 2
i = 0
print(len(CharLocArray))
while i < len(CharLocArray):
print(i)
CurStr = data[CharLocArray[i]:]
CurFolder = CurStr[CharLocArray[i]:NewLineArray[i]]
print(CurFolder)
CurData = CurStr[CharLocArray[i]:CharLocArray[i + 1]]
print(CurData)
newpath = r'/home/tjbutler/software/I-TASSER5.0/seqdata/Egg_protein/'
DirLocation = newpath + CurFolder
print(DirLocation)
FileLocation = DirLocation + '/seq.fasta'
print(FileLocation)
i = i + 1
print(i)
if not os.makedirs(DirLocation):
os.makedirs(DirLocation)
file = open(FileLocation, 'w+')
file.write(CurData)
file.close()