Python Learning Notes (28) file Management

Source: Internet
Author: User
Tags file type file

Vamei Source: Http://www.cnblogs.com/vamei Welcome reprint, Please also keep this statement. Thank you!

Original chain: http://www.cnblogs.com/vamei/archive/2012/09/14/2684775.html

NOTES: Learning more and more, is not forgetting more and more

#Nth- Speaking document management" "file management features command Linux-based file management features LS rename have to say that Linux basic commands are really generic Linux base commands.  Point to current directory: Point to Parent directory file additional information file type file Size file permissions file modify time file read Time ls-l file.txt-rw-rw-r--1 Liyihao liyihao 585 October 20:42 Key First-Indicates file type description ke Y is a regular file, the directory display drw-rw-r--represents the file permissions rw-rw-r--the owner owner owns the group owner, the other person otherlinux login, I will have a user identity as a group identity card rw-said I was changed The owner of the file has read R write W permission on this file, no execute permission, and execute permission-should be x second rw-indicates if my business card group ID proves I am this group, then I have permission to read and write third if I am not the owner nor the group, then I have only Read permission 1 to represent the hard connection har D Link Number link Countliyihao indicates that Liyihao is the owner of the file, the owner has permission to update the file permissions, rwxrwxrwx585 represents the file size, in bytes October 24 20:42 Indicates the file name after the last write time" "#OS Package#mkdir (path)#Os.mkdir (path[, mode])#path is the directory, mode sets the permission number for the directoryImportOspath='D:\\download\\new4'os.mkdir (path)Print(r'Catalog has been created', Path)#has created aImportTimetime.sleep (5) Os.rmdir (path)Print(r'directory has been removed')#It's not obvious, it's better to watch it with the next one. Create, then display all the directories, then remove the directory, and then refresh the display of all the directoriesImportOspath='d:\\test\\test'os.mkdir (path)Print(r'Catalog has been created', path)#Create a directorypath2='d:\\test'Files=Os.listdir (path2)Print(Files)#Show all files in this directory, including our new folderos.rmdir (path)#Remove the created test directoryFile2 =Os.listdir (path2)Print(file2)#Show all files in the directory#If the execution speed is fast, you can increase the time packet latency to see the PC's process#output [' button.py ', ' monkeytest.log ', ' monkeytest2.log ', ' monkeytest3.log ', ' monkeytest4.log ', ' Test ', ' ucliulanqi_ ' 707.apk ', ' yizuanbao2.apk ', ' yizuanbao_pro_1.0_980.apk ', ' yizuanbao_yz360.apk ']#[' button.py ', ' monkeytest.log ', ' monkeytest2.log ', ' monkeytest3.log ', ' monkeytest4.log ', ' ucliulanqi_707.apk ', ' yizuanbao2.apk ', ' yizuanbao_pro_1.0_980.apk ', ' yizuanbao_yz360.apk ']#You can see the missing test directory .#Os.rmdir is to delete empty directory, otherwise error OSError#os.remove (path)#delete the specified directory file#new TXT file in test, show all files, remove TXT file, show all files againImportOs,timetxt1= Open ('D:\\test\\1.txt','W')Print(Txt1.name) txt1.close () files= Os.listdir ('d:\\test')Print(Files) time.sleep (5) Os.remove ('D:\\test\\1.txt') File2= Os.listdir ('d:\\test')Print(file2)" "[' 1.txt ', ' button.py ', ' monkeytest.log ', ' monkeytest2.log ', ' monkeytest3.log ', ' monkeytest4.log ', ' ucliulanqi_ ' 707.apk ', ' yizuanbao2.apk ', ' yizuanbao_pro_1.0_980.apk ', ' yizuanbao_yz360.apk ' [' button.py ', ' monkeytest.log ', ' Monkeytest2.log ', ' monkeytest3.log ', ' monkeytest4.log ', ' ucliulanqi_707.apk ', ' yizuanbao2.apk ', ' yizuanbao_pro_1.0_ 980.apk ', ' yizuanbao_yz360.apk ']" "#Rename FileFile = Open ('D:\\test\\1.txt','W') File.close () Time.sleep (5) Os.rename ('D:\\test\\1.txt','D:\\test\\2.txt') files= Os.listdir ('d:\\test')Print(Files) os.remove ('D:\\test\\2.txt') File2= Os.listdir ('d:\\test')Print(file2) Os.stat ('d:\\test\\ucliulanqi_707.apk')#output Os.stat_result (st_mode=33206, st_ino=9007199254743530, st_dev=551390, St_nlink=1, St_uid=0, St_gid=0, st_size= 34561962, st_atime=1510121999, st_mtime=1510122000, st_ctime=1510121999)#Query the file information, similar to the above linux-l command#querying the current working directoryOS.GETCWD ()#Change path file permissions#os.chmod (Path,mode)#You can modify permissions for a file/directory#Mode Reference http://www.runoob.com/python/os-chmod.html#change file owner and owning group (only supported under Unix)#os.chown (path, UID, GID)#UID User ID#GID Group ID#Create a soft link#Os.symlink (SRC, DST)#SRC Original Address#DST Destination Address" "*************************************************** separate Shutil bag" "ImportShutilshutil.copy ('d:\\test\\ucliulanqi_707.apk','D:\\apktool')Print('Copy Success') Shutil.move ('d:\\apktool\\ucliulanqi_707.apk','d:\\360downloads')Print('Move Success')#copy move two commands

Note:

Python Learning Notes (28) file Management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.