Home > other >  Help me have a look
Help me have a look

Time:10-09

把指定文件夹中的所有文件名批量改为时+分+秒+2位随机数形式的名称

CodePudding user response:

 
the import the OSThe import time
Import the random


Path="e:/test/"
File=OS. Listdir # (path) access to the file name in the directory

For I in file:
Old_name=path + I
Re=old_name. Split ('/') [1]. The split ('. ') [1] # get suffix
Times=time. Strftime (' % H % M % S ') # to get minutes when
Time. Sleep (1)
Rand="'. Join (random sample (' 123456789 ', 2)) # for two random number after
New_name=path + STR (times) + rand + ' '+ # re together
OS. Rename (old_name new_name) # modified file name
Print (' file name is changed)

CodePudding user response:

Thanks for the great god help  , I run the first try
  • Related