示例#1
0
def prefix_folder(prefix, path):
	filepaths, parentdirs = parse_slide_folders(path)

	if len(filepaths) == 0:
		print("No slides found!")
		return

	for filepath in filepaths:
		parent_folder = filepath[0]
		filename = filepath[1]

		old_file = os.path.join(parent_folder, filename)
		new_filename = prefix + filename
		new_file = os.path.join(parent_folder, new_filename)
		print("Renaming slide %s to %s" % (old_file, new_file))
		sys.stdout.flush()

		safe_rename(old_file, new_file)

	for parentdir in parentdirs:
		parent_pieces = os.path.split(parentdir)
		new_folder = os.path.join(parent_pieces[0], prefix + parent_pieces[1])
		print("Renaming container %s to %s" % (parentdir, new_folder))
		sys.stdout.flush()

		safe_rename(parentdir, new_folder)
示例#2
0
文件: prefix.py 项目: iroc7/VELVEEVA
def prefix_folder(prefix, path):
    filepaths, parentdirs = parse_slide_folders(path)

    if len(filepaths) == 0:
        print("No slides found!")
        return

    for filepath in filepaths:
        parent_folder = filepath[0]
        filename = filepath[1]

        old_file = os.path.join(parent_folder, filename)
        new_filename = prefix + filename
        new_file = os.path.join(parent_folder, new_filename)
        print("Renaming slide %s to %s" % (old_file, new_file))
        sys.stdout.flush()

        safe_rename(old_file, new_file)

    for parentdir in parentdirs:
        parent_pieces = os.path.split(parentdir)
        new_folder = os.path.join(parent_pieces[0], prefix + parent_pieces[1])
        print("Renaming container %s to %s" % (parentdir, new_folder))
        sys.stdout.flush()

        safe_rename(parentdir, new_folder)
示例#3
0
def rename_slide(old, new, root=None, relink=True, verbose=False):
	THUMB_NAME = "-thumb.jpg"
	FULL_NAME = "-full.jpg"

	if root is None:
		root = '.' # current directory

	if not os.path.exists(old):
		raise IOError("%s does not exist" % old)

	if not is_slide(old):
		raise TypeError("%s is not a valid slide" % old)

	
	old_slide_name = os.path.basename(old)
	new_slide_name = os.path.basename(new)

	inner_file, slide_type = parse_slide(old)

	#relink first so we don't have to worry about adjusting file paths
	if relink:
		renamer = mv_refs(old_slide_name, new_slide_name)
		parse_folder(root, actions=[renamer], verbose=verbose)


	#rename inner file
	inner_pieces = os.path.splitext(inner_file)
	new_inner_file = os.path.join(old,new_slide_name+inner_pieces[1])
	safe_rename(inner_file, new_inner_file)

	#rename -thumb.jpg if it exists
	old_thumb = os.path.join(old,old_slide_name+THUMB_NAME)
	new_thumb = os.path.join(old,new_slide_name+THUMB_NAME)
	if os.path.exists(old_thumb): safe_rename(old_thumb,new_thumb)

	#rename -full.jpg if it exists
	old_full = os.path.join(old,old_slide_name+FULL_NAME)
	new_full = os.path.join(old,new_slide_name+FULL_NAME)
	if os.path.exists(old_full): safe_rename(old_full,new_full)

	#rename outer parent folder
	safe_rename(old, new)