文件拆分脚本 && powershell移动文件脚本
文件拆分脚本
每隔两行拆分成一个新文件。
import os
with open('Main.java', 'r', encoding='UTF-8') as file:
file_content = file.read()
file_parts = file_content.split('\n\n')
for i in range(len(file_parts)):
fp = open(f'{i + 1}.txt', 'w')
fp.close()
for row in file_parts[i].splitlines():
row = row[2:]
print(row)
with open(f'{i + 1}.txt', 'a') as new:
new.write(row)
new.write('\n')
powershell移动文件脚本
把同名图片和文件放到同名文件夹底下。
# 获取当前目录的所有文件
$files = Get-ChildItem -Recurse -File
# 从files中删除当前脚本文件
$files = $files | Where-Object { $_.FullName -ne $MyInvocation.MyCommand.Path }
foreach ($file in $files) {
# 获取文件的目录
$targetDir = $file.BaseName
if (Test-Path -Path $targetDir) {
Move-Item -Path $file.FullName -Destination $targetDir
}
else {
New-Item -ItemType Directory -Path $targetDir
Move-Item -Path $file.FullName -Destination $targetDir
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】