我正在尝试通过从csv文件中读取路径将文本文件从一个文件夹移动到另一个文件夹。首先,我创建目标文件夹,我想从现有文件夹中移动文件。我从csv文件中读取了现有的文件夹路径。我正在使用Windows平台。
这是我的代码:
select t.*
from t
where <criterion1> or <criterion2>
order by (case when <criterion1> then 1 else 2 end)
limit 1;
运行代码后出现此错误:
import os
import csv
import shutil
#csv_filename = raw_input('Enter CSV filename:')
with open('insurance_sample.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ';')
header = next(readCSV)
count = 0
for row in readCSV:
dirname = "/".join(('Sorted_Program',row[1],row[4],row[3],row[7]))
#if not os.path.exists(dirname):
#os.makedirs(dirname)
path = row[10]
moveto = dirname
print path
print moveto
print os.path.isfile(path)
files = os.listdir(path)
print files
files.sort()
for f in files:
src = path + f
dst = moveto + f
break
如果问题仍然令人困惑,请告诉我,我会尝试更详细地解释。
答案 0 :(得分:0)
所以看来这里有两个问题:
/
创建目录引用,而Windows目录需要\
\
尝试以下修改:
dirname = "\\" + "\\".join(('Sorted_Program',row[1],row[4],row[3],row[7]))