找回密码
 欢迎注册
查看: 61|回复: 1

[讨论] 代码与法律

[复制链接]
发表于 5 天前 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
https://www.zhihu.com/question/12523235406
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 5 天前 | 显示全部楼层
我在QQ群里找人替我定制软件。过了段时间他说好了,就下载了他的脚本。他要求我付款,我没有付款。然后我运行了那个脚本,检验他的功能对不对。后来发现功能错了。联系那人又不在线。

如果他告我没付款,我说他的软件功能不对,等他功能改正了再付款,改正之前不付。法律是否支持?谁能证明他的功能不对,也许换了台电脑功能又正常了?

要求的功能:逐字节比较两文件二进制数据,从头到尾相同位置完全相等就是相同文件。

a目录有的文件,就只留一份,其他相同的删除。a目录没有的,b目录里面的,就只保留b目录的

  1. function Compare-FilesByteByByte {

  2. param (

  3. [string]$FilePath1,

  4. [string]$FilePath2

  5. )


  6. # 检查文件大小是否相同

  7. $file1Size = (Get-Item $FilePath1).Length

  8. $file2Size = (Get-Item $FilePath2).Length

  9. if ($file1Size -ne $file2Size) {

  10. return $false

  11. }


  12. # 打开文件流

  13. $stream1 = [System.IO.File]::OpenRead($FilePath1)

  14. $stream2 = [System.IO.File]::OpenRead($FilePath2)


  15. try {

  16. # 逐字节比对

  17. for ($i = 0; $i -lt $file1Size; $i++) {

  18. $byte1 = $stream1.ReadByte()

  19. $byte2 = $stream2.ReadByte()


  20. if ($byte1 -ne $byte2) {

  21. return $false

  22. }

  23. }


  24. return $true

  25. }

  26. finally {

  27. # 关闭文件流

  28. $stream1.Close()

  29. $stream2.Close()

  30. }

  31. }


  32. function Remove-DuplicateFiles {

  33. param (

  34. [string[]]$Folders

  35. )


  36. # 用于存储已检查的文件路径

  37. $checkedFiles = @()


  38. # 遍历所有文件夹

  39. foreach ($folder in $Folders) {

  40. # 获取文件夹中的所有文件

  41. $files = Get-ChildItem -Path $folder -Recurse -File


  42. foreach ($file in $files) {

  43. $isDuplicate = $false


  44. # 与已检查的文件逐字节比对

  45. foreach ($checkedFile in $checkedFiles) {

  46. if (Compare-FilesByteByByte -FilePath1 $file.FullName -FilePath2 $checkedFile) {

  47. $isDuplicate = $true

  48. Write-Host "发现重复文件: $($file.FullName) 与 $checkedFile"

  49. # 删除当前文件

  50. Remove-Item -Path $file.FullName -Force

  51. Write-Host "已删除文件: $($file.FullName)"

  52. break

  53. }

  54. }


  55. # 如果文件不是重复的,则添加到已检查的文件列表中

  56. if (-not $isDuplicate) {

  57. $checkedFiles += $file.FullName

  58. }

  59. }

  60. }

  61. }


  62. # 文件夹路径

  63. $folderA = "C:\Users\Administrator\Documents\新建文件夹 (2)"

  64. $folderB = "C:\Users\Administrator\Desktop\新建文件夹2"

  65. $folderC = "D:"


  66. Remove-DuplicateFiles -Folders @($folderA, $folderB, $folderC)
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2025-2-22 15:01 , Processed in 0.038245 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表