added function get_file

This commit is contained in:
Rushabh Mehta 2012-05-16 15:38:11 +05:30
parent b0f496c4d2
commit 57b72f82c0

View file

@ -211,4 +211,20 @@ def delete_file(fid, verbose=0):
webnotes.conn.sql("delete from `tabFile Data` where name=%s", fid)
path = os.path.join(webnotes.get_files_path(), fid.replace('/','-'))
if os.path.exists(path):
os.remove(path)
os.remove(path)
def get_file(fname):
f = get_file_system_name(fname)
if f:
file_id = f[0][0].replace('/','-')
file_name = f[0][1]
else:
file_id = fname
file_name = fname
# read the file
import os
with open(os.path.join(webnotes.get_files_path(), file_id), 'r') as f:
content = f.read()
return [file_name, content]