CustomUploadAndFilters: fs.py

File fs.py, 939 bytes (added by Enrico <rico.bl@…>, 18 years ago)

Filesystem utilities for custom upload fields

Line 
1import os
2
3def change_basename(file_path, new_name):
4 # Extract path: 'news/img'
5 path = os.path.dirname(file_path)
6
7 # Extract current name: 'name.jpg'
8 curr_name = os.path.basename(file_path)
9 # Split file name and extension: 'name', '.jpg'
10 original, ext = os.path.splitext(curr_name)
11
12 # Return the new path: 'news/img/new_name.jpg'
13 return os.path.join(path, new_name + ext).replace('\\', '/')
14
15# def change_basename
16
17def add_to_basename(file_path, str):
18 # Extract path: 'news/img'
19 path = os.path.dirname(file_path)
20
21 # Extract current name: 'name.jpg'
22 curr_name = os.path.basename(file_path)
23 # Split file name and extension: 'name', '.jpg'
24 original, ext = os.path.splitext(curr_name)
25
26 # Return the new path: 'news/img/originalstr.jpg'
27 return os.path.join(path, original + str + ext).replace('\\', '/')
28
29# def add_to_basename
Back to Top