1

I have this folder structure:

folder_tree

In mixed folder there are various file which have, as first char of the name, a digit from 0 to 9. What I want to do is to move all files which begins with 0 to the 0 folder, all which begin with 1 to 1 folder and so on..

I tried this solution but it doesn't seems to work.

lucians
  • 2,239
  • 5
  • 36
  • 64

1 Answers1

1

You can use the os module.

import os
path = <path_of_main_folder>
for file in os.listdir(path + '\\mixed'):
    full_path = path + '\\mixed\\' + file
    os.rename(full_path, path + '\\' + file[0] + '\\' + file) #move from mixed to folder w/ same first char
Primusa
  • 13,136
  • 3
  • 33
  • 53