file operation note

从HLE回来,大家拍了2499张照片,分放在N个文件夹下,下面的python将下层目录中文件移动到上层

 1 import os,shutil
 2 
 3 dst=os.getcwd()+os.sep
 4 
 5 
 6 for path in os.listdir('.'):
 7     if os.path.isdir(path):
 8         os.chdir(path)
 9         for file in os.listdir('.'):
10             print file
11             ful=os.getcwd()+os.sep+file
12             os.rename(ful,dst+file)
13         os.chdir('..')

0607加完一天班,回来传图片到QQ(小装一下^^),每次只能传300张,重命名目录下所有照片的名字为(0.jpe,1.jpg...还是自己起的名字好记)

1 import os
2 
3 i=0
4 
5 os.chdir('tph')
6 dstpath=os.getcwd()+os.sep
7 for fname in os.listdir('.'):
8     os.rename(dstpath+fname,dstpath+str(i)+'.jpg') 
9     i=i+1

 拷贝suse 壁纸脚本

 1 #!/bin/sh                                                                                            
 2 
 3 dircnt=0
 4 jcnt=0
 5 for dirnm  in `ls wallpapers`
 6 do
 7 dircnt=$(ls wallpapers/${dirnm}/contents/images/ | wc -l)
 8 
 9 if [ $dircnt -gt 0 ];then
10 for jf in `ls wallpapers/${dirnm}/contents/images/`
11 do
12 cp wallpapers/${dirnm}/contents/images/${jf} /home/joh/out/${dirnm}_${jcnt}.jpg
13 echo $jf
14 jcnt=`expr $jcnt + 1`
15 echo $jcnt
16 done
17 fi
18 done

to be continue

原文地址:https://www.cnblogs.com/eiguleo/p/3773625.html