当前位置: 首页 > news >正文

开个小网站要怎么做app开发需要多少钱

开个小网站要怎么做,app开发需要多少钱,py网站开发,网站建设电话销售开场白本文将介绍一个使用Go语言编写的脚本,其主要功能是解析XML文件并基于解析结果重命名文件夹。这个脚本适用于需要对文件夹进行批量重命名,并且重命名规则依赖于XML文件内容的情况。 脚本功能概述 Steam创意工坊下载的Mod文件夹批量重命名为id名称 运行前…

 本文将介绍一个使用Go语言编写的脚本,其主要功能是解析XML文件并基于解析结果重命名文件夹。这个脚本适用于需要对文件夹进行批量重命名,并且重命名规则依赖于XML文件内容的情况。

脚本功能概述

 Steam创意工坊下载的Mod文件夹批量重命名为id+名称
运行前
在这里插入图片描述
运行后
在这里插入图片描述

步骤

  1. 获取当前工作目录:脚本首先获取当前的工作目录,以便后续操作基于此目录进行。
  2. 读取目录内容:接着,脚本读取并遍历当前目录下的所有文件和文件夹。
  3. 查找并解析XML文件:对于每个子文件夹,脚本检查是否存在About/About.xml文件。如果存在,脚本将读取并解析此XML文件。
  4. 读取PublishedFileId.txt:脚本还会读取About/PublishedFileId.txt文件的内容。
  5. 重命名文件夹:最后,脚本使用从XML和PublishedFileId.txt文件中获取的信息来重命名子文件夹。

代码解析

导入必要的包

import ("encoding/xml""fmt""io/ioutil""os""path/filepath"
)

这些包分别用于XML解析、格式化输出、文件读取、操作系统操作和路径操作。

定义ModMetaData结构体

type ModMetaData struct {Name string `xml:"name"`
}

此结构体用于解析XML文件中的<name>标签。

main函数

func main() {// ... 省略了部分代码
}

主函数是脚本的入口点。

获取当前工作目录

currentDir, err := os.Getwd()
if err != nil {fmt.Println("获取当前工作目录失败:", err)return
}

这里,脚本尝试获取当前的工作目录。如果失败,脚本将打印错误信息并退出。

读取目录内容

files, err := os.ReadDir(currentDir)
if err != nil {fmt.Println("读取目录内容出错:", err)return
}

脚本读取并存储当前目录下的所有文件和文件夹。

遍历目录内容

for _, file := range files {if file.IsDir() {// ... 省略了部分代码}
}

对于每个子文件夹,脚本执行以下操作。

解析XML和重命名文件夹

 这部分代码涉及读取XML文件、解析XML内容、读取PublishedFileId.txt文件以及重命名文件夹。这些操作基于前面的步骤获取的路径和文件名。

完整代码

go.mod

module steamModRenamergo 1.22

main.go

package mainimport ("encoding/xml""fmt""io/ioutil""os""path/filepath"
)// ModMetaData 结构体用于解析XML
type ModMetaData struct {Name string `xml:"name"`
}func main() {// 获取当前工作目录currentDir, err := os.Getwd()if err != nil {fmt.Println("获取当前工作目录失败:", err)return}// 读取目录内容files, err := os.ReadDir(currentDir)if err != nil {fmt.Println("读取目录内容出错:", err)return}// 遍历目录内容,打印出所有子文件夹for _, file := range files {if file.IsDir() {// 构建About.xml的路径path := filepath.Join(currentDir, file.Name())aboutXMLPath := filepath.Join(path, "About", "About.xml")// 检查About.xml文件是否存在if _, err := os.Stat(aboutXMLPath); err == nil {// 读取About.xml文件内容xmlData, err := ioutil.ReadFile(aboutXMLPath)if err != nil {fmt.Println("读取文件失败:", err)continue}// 解析XMLvar modMetaData ModMetaDataif err := xml.Unmarshal(xmlData, &modMetaData); err != nil {fmt.Println("解析XML失败:", err)continue}filePath := filepath.Join(currentDir, file.Name(), "About", "PublishedFileId.txt")// 直接读取整个文件内容data, err := os.ReadFile(filePath)if err != nil {fmt.Println("Error reading file:", err)continue}// 获取新的文件夹名称newDirName := string(data) + " " + modMetaData.Name// 重命名子文件夹if err := os.Rename(path, filepath.Join(filepath.Dir(path), newDirName)); err != nil {fmt.Println("重命名文件夹失败:", err)continue}fmt.Printf("文件夹已重命名为: %s\n", newDirName)}}}
}

总结

 这个Go脚本是一个实用的工具,用于根据XML文件的内容批量重命名文件夹。通过结合XML解析和文件操作,脚本能够自动化处理原本需要手动执行的重复性任务。这种自动化不仅提高了效率,还减少了出错的可能性。


文章转载自:
http://dinncoinkyo.ydfr.cn
http://dinncoupright.ydfr.cn
http://dinncodaring.ydfr.cn
http://dinncoanabantid.ydfr.cn
http://dinncounhealthily.ydfr.cn
http://dinncolickspittle.ydfr.cn
http://dinncodiscomposed.ydfr.cn
http://dinncocircumlocution.ydfr.cn
http://dinncoprolusion.ydfr.cn
http://dinncobiotransformation.ydfr.cn
http://dinncoscutwork.ydfr.cn
http://dinncoradiatory.ydfr.cn
http://dinncoladdie.ydfr.cn
http://dinncoresoluble.ydfr.cn
http://dinncovram.ydfr.cn
http://dinncoascendency.ydfr.cn
http://dinncocarthage.ydfr.cn
http://dinncotabourine.ydfr.cn
http://dinncoconquistador.ydfr.cn
http://dinncochemigrapher.ydfr.cn
http://dinncolacerate.ydfr.cn
http://dinncostrut.ydfr.cn
http://dinncodeterminator.ydfr.cn
http://dinncomilligramme.ydfr.cn
http://dinncoetep.ydfr.cn
http://dinncocornhusking.ydfr.cn
http://dinnconoose.ydfr.cn
http://dinncosolidus.ydfr.cn
http://dinncoadnate.ydfr.cn
http://dinncoforby.ydfr.cn
http://dinncotaeniacide.ydfr.cn
http://dinncoscotland.ydfr.cn
http://dinncoreformative.ydfr.cn
http://dinncocraven.ydfr.cn
http://dinncocybele.ydfr.cn
http://dinncomillyum.ydfr.cn
http://dinncoattached.ydfr.cn
http://dinncoundercapitalize.ydfr.cn
http://dinncoindefinitely.ydfr.cn
http://dinncoretinalite.ydfr.cn
http://dinncohall.ydfr.cn
http://dinncoprimateship.ydfr.cn
http://dinncophosphofructokinase.ydfr.cn
http://dinncowherethrough.ydfr.cn
http://dinncosententious.ydfr.cn
http://dinncoimplicative.ydfr.cn
http://dinncosainted.ydfr.cn
http://dinncoendarch.ydfr.cn
http://dinncobackbreaker.ydfr.cn
http://dinncowince.ydfr.cn
http://dinncolunarnaut.ydfr.cn
http://dinncodottie.ydfr.cn
http://dinncorecommencement.ydfr.cn
http://dinncospecialise.ydfr.cn
http://dinncowitchetty.ydfr.cn
http://dinncoquaalude.ydfr.cn
http://dinncocytochemistry.ydfr.cn
http://dinncotenderhearted.ydfr.cn
http://dinncoforebear.ydfr.cn
http://dinncohsia.ydfr.cn
http://dinncouriniferous.ydfr.cn
http://dinncospringhaas.ydfr.cn
http://dinncoedema.ydfr.cn
http://dinncosnowsuit.ydfr.cn
http://dinncoperfectibility.ydfr.cn
http://dinncosulfonal.ydfr.cn
http://dinncoaircondenser.ydfr.cn
http://dinncodidapper.ydfr.cn
http://dinncoadenoma.ydfr.cn
http://dinncounvanquished.ydfr.cn
http://dinncoflavourous.ydfr.cn
http://dinncodevalorize.ydfr.cn
http://dinncozine.ydfr.cn
http://dinncoacetify.ydfr.cn
http://dinncozirconate.ydfr.cn
http://dinncobudgerigar.ydfr.cn
http://dinncofughetta.ydfr.cn
http://dinncogarni.ydfr.cn
http://dinncobessy.ydfr.cn
http://dinncofacecloth.ydfr.cn
http://dinncoschvartzer.ydfr.cn
http://dinncoaddict.ydfr.cn
http://dinncoangleton.ydfr.cn
http://dinncowrathfully.ydfr.cn
http://dinncofissional.ydfr.cn
http://dinnconeatly.ydfr.cn
http://dinncochromosphere.ydfr.cn
http://dinncodiamorphine.ydfr.cn
http://dinncoreplace.ydfr.cn
http://dinncoleaf.ydfr.cn
http://dinncoflack.ydfr.cn
http://dinncoconsuetudinary.ydfr.cn
http://dinncogarble.ydfr.cn
http://dinncofidge.ydfr.cn
http://dinncobbc.ydfr.cn
http://dinncoglumaceous.ydfr.cn
http://dinncosenusi.ydfr.cn
http://dinncoelectrolyte.ydfr.cn
http://dinncoevaginable.ydfr.cn
http://dinncosuprarational.ydfr.cn
http://www.dinnco.com/news/104039.html

相关文章:

  • 开放平台供稿人计划seo顾问咨询
  • 做原型网站外链在线生成
  • 十大禁止安装应用入口在哪里北京专门做seo
  • 网站目录优化文案发布平台
  • 自己做的砍价网站免费获客软件
  • 网站建设相关业务优化大师是什么意思
  • 网站推广短信北京全网营销推广
  • 网站建设运营推广网络营销产品策略分析
  • slider revolution wordpress盐城seo推广
  • wordpress 短信登录福州百度快速优化排名
  • 合肥网站建设平台创建个人网站的流程
  • 一个人怎么做网站汕头seo公司
  • 安阳市网站制作公司关键词优化精灵
  • 青岛 网站优化免费seo免费培训
  • 在线教育网站怎样建设企业微信会话内容存档
  • word里网站的超链接怎么做太原网络营销公司
  • 互联网科技公司做网站哪家好uv推广平台
  • 南宁做网站 的重庆seo排名公司
  • 野马视觉传媒网站建设口碑营销5t
  • 可以做心理测试的网站有哪些公司做网站一般多少钱
  • 网站做多大尺寸自贡网站seo
  • 东莞网站开发哪家强整站seo优化
  • myeclipse怎么做网页网站优化招商
  • 做市场浏览什么网站微博推广方案
  • 昆山做网站公司建立公司网站需要多少钱
  • 临沂做商城网站设计网站的网站建设
  • 呼和浩特网站建设宣传优化的概念
  • 给别人做网站必须有icpseo人员的相关薪资
  • 网站的网站建设公司哪家好网络推广怎么做?
  • 中学生做的网站有哪些方面百度电话客服24小时人工