@@ -28,20 +28,20 @@ def _get_next_path(path):
2828 '''
2929 assert isinstance (path , pathlib .Path )
3030 suffix = path .suffix
31- suffixless_last_part = path .parts [ - 1 ][ :- len (suffix )]
32- head = str (path )[:- len (path .parts [ - 1 ] )]
33- assert pathlib .Path ('{}{}{}' .format (head ,
34- suffixless_last_part , suffix )) == path
35- match = numbered_name_pattern .match (suffixless_last_part )
31+ suffixless_name = path .name [ :- len (suffix )] if suffix else path . name
32+ parent_with_separator = str (path )[:- len (path .name )]
33+ assert pathlib .Path ('{}{}{}' .format (parent_with_separator ,
34+ suffixless_name , suffix )) == path
35+ match = numbered_name_pattern .match (suffixless_name )
3636 if match :
3737 fixed_suffixless_name = '{} ({})' .format (
3838 match .group ('raw_name' ),
3939 int (match .group ('number' ))+ 1 ,
4040 )
4141 else :
42- fixed_suffixless_name = '{} (1)' .format (suffixless_last_part ,)
42+ fixed_suffixless_name = '{} (1)' .format (suffixless_name ,)
4343 return pathlib .Path (
44- '{}{}{}' .format (head , fixed_suffixless_name , suffix )
44+ '{}{}{}' .format (parent_with_separator , fixed_suffixless_name , suffix )
4545 )
4646
4747
@@ -62,12 +62,12 @@ def iterate_file_paths(path):
6262
6363def create_folder_renaming_if_taken (path ):
6464 '''
65- Create a new folder with name `path` for writing , renaming if name taken.
65+ Create a new folder with name `path`, renaming it if name taken.
6666
67- If the name given is "example", the new name would be "example
68- (1)", and if that's taken "example (1 )", and so on.
67+ If the name given is "example", the new name would be "example (1)", and if
68+ that's taken "example (2 )", and so on.
6969
70- Returns a path object to the newly-created folder
70+ Returns a path object to the newly-created folder.
7171 '''
7272 for path in cute_iter_tools .shorten (iterate_file_paths (pathlib .Path (path )),
7373 N_MAX_ATTEMPTS ):
0 commit comments