From 57b72f82c0beab2cceedeba4e354b8b578383edc Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 16 May 2012 15:38:11 +0530 Subject: [PATCH] added function get_file --- py/webnotes/utils/file_manager.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/py/webnotes/utils/file_manager.py b/py/webnotes/utils/file_manager.py index d63d5b751a..bba3624cca 100644 --- a/py/webnotes/utils/file_manager.py +++ b/py/webnotes/utils/file_manager.py @@ -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) \ No newline at end of file + 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] \ No newline at end of file