python磁盘拷贝练习

1、讲博客、用户关系数据持久化

import sys
import pickle


# users保存所有注册成功的用户
users = []


def menu1():
    print("欢迎登录我们的用户管理系统")
    print("\t\t 1、用户注册")
    print("\t\t 2、用户登录")
    print("\t\t 3、退出系统")


def user_exists(username):
    for u in users:
        if u.get("username") == username:
            print("对不起,该用户已经存在,请重新注册")
            return u
    return None


def reg_check(username, password, confirm_password):
    # 数据校验
    # 用户名称不能为空
    if username == None or len(username) == 0:
        print("对不起,用户为空")
        return False

    # 用户名称不能重复
    u = user_exists(username)
    if u != None:
        return False

    # 密码长度不能少于3if len(password) < 3:
        print("对不起,密码长度不能少于3位")
        return False
    # 两次密码不一致
    if password != confirm_password:
        print("两次密码不一致")
        return False

    return True


def reg():
    while True:
        # 接受参数
        print("欢迎进入到用户注册页面")
        username = input("请输入用户名称:")
        password = input("请输入用户密码:")
        confirm_password = input("请再次确认密码:")

        # 数据校验
        if not reg_check(username, password, confirm_password):
            continue

        # 最后如何保存用户名称和密码
        # 加密密码
        md5_pass = my_utils.md5_by_hashlib(password)

        user = {"username": username, "password": md5_pass}
        users.append(user)
        print("用户注册成功,请登录")
        break


def login():
    print("欢迎进入到用户登录页面")
    username = input("请输入用户名称:")
    password = input("请输入用户密码:")

    # 判断用户名和密码是否存在于users
    user = user_exists(username)
    if user == None:
        print("登录失败,该用户名不存在!!!")
    else:
        # 判断密码
        md5_pass = my_utils.md5_by_hashlib(password)
        if user.get("password") == md5_pass:
            print("恭喜您,{},登录成功".format(username))
        else:
            print("登录失败,密码错误!!!")


def user_selected(choice):
    if choice == "1":
        reg()

    elif choice == "2":
        login()

    elif choice == "3":
        sys.exit()
    else:
        print("输入有误,请重新选择")

def  serialization(ls):



    pickle.dump(ls, open("E:\练习.txt", mode="wb"))  # 持久化数据,将ls放在路径下
    pickle.load(open("E:\练习.txt", mode="br"))  # 反序列化读取数据


while True:
    menu1()
    choice = input("请选择您的操作:")
    user_selected(choice)
    serialization(choice)

拷贝文件(一定要会),在拷贝基础上 + 遍历磁盘基础上 ==> 实现磁盘复制

from os import path
import uuid
import sys
import os

def file(url):
    files=os.listdir(url)
    for i in files  :
        path=os.path.join(url,i)
        if os.path.isfile(path) :
            print(path)
        elif os.path.isdir(path) :
            #如果是文件夹,递归遍历
            file(path)
if len(sys.argv) <2 :
   print("必须传递参数")
else:
    p=sys.argv[1]
    file(p)
file("E:\jhj\IT作业\Linux私房菜")

def copy(file1, file2):
	while True:
		content = file1.read(2048)
		if content != b'':
			file2.write(content)
		else:
			break


def copy_by_bytes(src, dest):
	if not path.isfile(src):
		print("对不起,路径有误")
		return
	file1 = open(src, "br")
	# 注意:不建议直接将所有数据丢读取到内存中,很容易出现内存不够用,导致蓝屏现象
	# file2.write(file1.read())

	# 判断dest是不是文件夹
	if path.isfile(dest):
		file2 = open(dest, "bw")
		copy(file1, file2)

	elif path.isdir(dest):
		filename = src[src.rindex("\\") + 1:]
		p = path.join(dest, str(uuid.uuid4()) + filename)
		file2 = open(p, "bw")
		copy(file1, file2)

	print("读取成功")
	file1.close()
	file2.close()


copy_by_bytes("E:\jhj\IT作业\Linux私房菜","E:\IT笔记\开发")

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
********************************* Date : Wed Dec 30 09:57:51 2009 Error Number: (19330) Message: EstimateFatClustersUsed: Unknown fat_type: 0 Version: 11.0.2.1573 (Nov 14 2007, Build=1573) OS Version: Microsoft Windows XP Professional Service Pack 3 (Build 2600) Command line arguments: Active Switches : AutoName PathName : DumpFile : DumpPos : 0 FlagImplode : 0 FlagExplode : 0 Operation Details : Total size.........0 MB copied..........0 MB remaining.......0 Percent complete...0% Speed..............0 MB/min Time elapsed.......0:00 Time remaining.....0:00 Program Call Stack AbortLog Generic_Abort localEstimateFatClustersUsed EstimateFatClustersUsed CheckFatPartition CheckPartition AddAPartition NormalGetAllPartInfo GetAllPartInfo GetDriveData PaintDisplayDriveData CopyPartToFile CopyMainline AttemptOperation sub_main main Call Stack Address Frame Logical Addr Module 0x000000007c92e514 0x000000000012d134 KiFastSystemCallRet+0x0000000000000000 0x000000000012d434 0x0000000000000003 0x0000:0x0000000000000000 End Call Stack Start heap available: 1544273920 Cur heap available: 1543098368 Total Memory: 1877454848 Allocated 33500 ..\ghost.cpp:1396 Free Fat details: NTFS details: ---------------- NTFS Global Flags: ---------------- contiguousWrite=1 forceDiskClusterMapping=0 inhibitCHKDSK=1 ignoreBadLog=0 ignoreCHKDSKBit=0 enable_cache=0 xfrbuflen=0 last_attr_type = 0 loadExact = 0 ---------------- ======================================================= NTFS volume 0: ---------------- initialised..............1 read cached..............N Selective caching........N flags....................Volume OK drive....................0x00 part order...............0 version..................0x0400 volsize..................40960016 blocksize................512 clusterfactor............8 clustersize..............4096 mftrecordsize............1024 indexrecordsize..........4096 indexclustperrecord......1 bootSectorCopyOffset.....40960016 pagefileSys..............-1 bootIni..................-1 volumeLabel..............[] sectorsInUse.............133232 totalNonCopiedBytes......0 bytesToCopy..............0 bitmapClusters...........157 bitmapUsedBytes..........640008 estimatedClusters........157 estimatedUsedBytes.......640008 clustersizeShift.........12 blocksizeShift...........9 mftrecordsizeShift.......10 indexrecordsizeShift.....12 totalRootMftRecs.........0 clustermap failover......N Boot sector details name....................[NTFS ] blocksize...............512 clusterfactor...........8 reservedSectorsUnused...0 mediaType...............0xf8 secPerTrack.............63 numHeads................240 hiddenSectors...........63 volsize.................40960016 mftcluster..............786432 mftmirrorcluster........2560001 clustersPerMFTRecord....246 clustersPerIndexBuffer..1 --------------------------------------------------- Cluster Allocation Map --------------------------------------------------- Start: 5120002 Length: 0 Next: 5120002 ======================================================= Disk Info : remote.............0 drive..............0 sectorsUsedCount.......92159109 estimatedUsedCount.....133232 numPartitions..............2 Version............0 # Ord Boot Id Ext First Num Last Used NTFS 0 0 1 7 No 63 40960017 40960080 133232 Yes 1 1 0 b Yes 40971483 51199092 92170575 0 No Disk Info : remote.............0 drive..............0 sectorsUsedCount.......0 estimatedUsedCount.....0 numPartitions..............0 Version............0 # Ord Boot Id Ext First Num Last Used NTFS Fixed Drives Drive 0 Hitachi HDS721616PLAT80 PV5301ZHSYEYEM WinNT (Active) Total Sectors 321670847 Bytes per Sector 512 MB 157065 Cylinders 21274 Heads 240 Sectors per Track 63 Successful IO Count 59 Drive 1 ST3160815AS 5RA9NDH2 WinNT (Active) Total Sectors 312579695 Bytes per Sector 512 MB 152626 Cylinders 19457 Heads 255 Sectors per Track 63 Successful IO Count 38 Remote Drives AsyncIo : 0 Image Devices Key[1] 1.1: Key[2] 1:1 Key[3] K: Path K: Desc K: 1.1: [] Type NTFS Disk 0 Offset 63 Key[1] 1.3: Key[2] 1:3 Key[3] L: Path L: Desc L: 1.3: [] Type FAT Disk 0 Offset 176420223 Key[1] 1.4: Key[2] 1:4 Key[3] M: Path M: Desc M: 1.4: [] Type NTFS Disk 0 Offset 260245503 Key[1] 2.1: Key[2] 2:1 Key[3] C: Path C: Desc C: 2.1: [] Type NTFS Disk 1 Offset 63 Key[1] 2.2: Key[2] 2:2 Key[3] D: Path D: Desc D: 2.2: [] Type NTFS Disk 1 Offset 9221373 Key[1] 2.3: Key[2] 2:3 Key[3] G: Path G: Desc G: 2.3: [巨人] Type FAT Disk 1 Offset 224299593 Key[1] E: Path E: Desc E: [软件] Type Disk Key[1] F: Path F: Desc F: [冷之客] Type Disk Key[1] H: Path H: Desc H: [青苹果家园纯净版V5.0] Type CD Key[1] @CD-R1 Path @CD-R1 Desc @CD-R1 Optiarc DVD-ROM DDU1671S Type DVD DiskManager diagnostic... ========================= Fixed Drives Drive 0 Hitachi HDS721616PLAT80 PV5301ZHSYEYEM WinNT (Active) Total Sectors 321670847 Bytes per Sector 512 MB 157065 Cylinders 21274 Heads 240 Sectors per Track 63 Successful IO Count 59 Drive 1 ST3160815AS 5RA9NDH2 WinNT (Active) Total Sectors 312579695 Bytes per Sector 512 MB 152626 Cylinders 19457 Heads 255 Sectors per Track 63 Successful IO Count 38 FilesystemManager diagnostic... =============================== Volume 1 VolumePos: 1.1: DriveLetter: K: Description: 19.53GB Primary Disk 0 Offset 31.50KB 19.53GB Hitachi HDS721616PLAT80 PV5301ZHSYEYEM Type: fsfNtfsWindowsXP Name: Volume 2 VolumePos: 1.3: DriveLetter: L: Description: 39.97GB Logical Disk 0 Offset 84.12GB 39.97GB Hitachi HDS721616PLAT80 PV5301ZHSYEYEM Type: fsfFat32 Name: Volume 3 VolumePos: 1.4: DriveLetter: M: Description: 29.29GB Logical Disk 0 Offset 124.09GB 29.29GB Hitachi HDS721616PLAT80 PV5301ZHSYEYEM Type: fsfNtfsWindowsXP Name: Volume 4 VolumePos: 2.1: DriveLetter: C: Description: 4.40GB Primary Disk 1 Offset 31.50KB 4.40GB ST3160815AS 5RA9NDH2 Type: fsfNtfsWindowsXP Name: Volume 5 VolumePos: 2.2: DriveLetter: D: Description: 24.42GB Logical Disk 1 Offset 4.40GB 24.42GB ST3160815AS 5RA9NDH2 Type: fsfNtfsWindowsXP Name: Volume 6 VolumePos: 2.3: DriveLetter: G: Description: 42.09GB Logical Disk 1 Offset 106.95GB 42.09GB ST3160815AS 5RA9NDH2 Type: fsfFat32 Name: FilesystemMounter diagnostic... =============================== LfoFilesystemManager diagnostic... ================================== Filesystem Index: 0 Filesystem Descriptor: ID's: ID Type: 2 ID: C: ID Type: 1 ID: 2.1: DriveType: 4 FilesystemInfo: formatType: 8 volumeName: Filesystem Index: 1 Filesystem Descriptor: ID's: ID Type: 2 ID: D: ID Type: 1 ID: 2.2: DriveType: 4 FilesystemInfo: formatType: 8 volumeName: Filesystem Index: 2 Filesystem Descriptor: ID's: ID Type: 2 ID: E: DriveType: 4 No FilesystemInfo structure. Filesystem has no VolumePtr Filesystem Index: 3 Filesystem Descriptor: ID's: ID Type: 2 ID: F: DriveType: 4 No FilesystemInfo structure. Filesystem has no VolumePtr Filesystem Index: 4 Filesystem Descriptor: ID's: ID Type: 2 ID: G: ID Type: 1 ID: 2.3: ID Type: 4 ID: : DriveType: 4 FilesystemInfo: formatType: 3 volumeName: Filesystem Index: 5 Filesystem Descriptor: ID's: ID Type: 2 ID: H: DriveType: 8 No FilesystemInfo structure. Filesystem has no VolumePtr Filesystem Index: 6 Filesystem Descriptor: ID's: ID Type: 2 ID: I: ID Type: 1 ID: 1.2: DriveType: 4 No FilesystemInfo structure. Filesystem Index: 7 Filesystem Descriptor: ID's: ID Type: 2 ID: K: ID Type: 1 ID: 1.1: DriveType: 4 FilesystemInfo: formatType: 8 volumeName: Filesystem Index: 8 Filesystem Descriptor: ID's: ID Type: 2 ID: L: ID Type: 1 ID: 1.3: DriveType: 4 FilesystemInfo: formatType: 3 volumeName: Filesystem Index: 9 Filesystem Descriptor: ID's: ID Type: 2 ID: M: ID Type: 1 ID: 1.4: DriveType: 4 FilesystemInfo: formatType: 8 volumeName: *********************************

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

韶光不负

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值