标题: [文件操作] [已解决]批处理怎样把数量超过1000文件自动分为多份? [打印本页]
作者: 任贤齐 时间: 2021-5-24 09:48 标题: [已解决]批处理怎样把数量超过1000文件自动分为多份?
d盘a目录下有3000个html文件,想要把这3000个文件插入到xml里面,一次性插入代码如下(已测试成功)
因为有数量的限制,现在想实现的是每超过1000个html,则生成多个文件
比如1000以内 生成text.xml
1000-2000 就生成 text.xml text1.xml
2000-3000 就生成 text.xml(1-1000) text1.xml(1000-2000) text2.xml(2000-3000) 这样
请问各位大神如何修改?
一次性插入代码:- @powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
- $xml = @'
- <?xml version="1.0" encoding="utf-8"?>
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
- <url>
- <loc>http://www.baidu.com/</loc>
- <changefreq>daily</changefreq>
- <priority>1.00</priority>
- </url>
- {0}
- </urlset>
- '@
- $url = @'
-
- <url>
- <loc>http://www.baidu.com/{0}</loc>
- <changefreq>daily</changefreq>
- <priority>0.8</priority>
- </url>
- '@
- $endl = "`r`n"
- $urls = ''
- Get-ChildItem '*.html' | foreach { $urls += $url -f $_.Name }
- $xml -f $urls | Out-File 'test.xml'
- 'test.xml'
复制代码
作者: 任贤齐 时间: 2021-5-24 23:26
不知道有大神知道吗 谢谢
作者: newswan 时间: 2021-5-26 11:37
本帖最后由 newswan 于 2021-5-26 12:59 编辑
- $endl = "`r`n"
-
- $urls = @()
- $n=(get-childitem *.html).count
- for ($x=0 ; $x -le $n ; $x++) {
- $urls += ""
- }
-
- $i=0
- Get-ChildItem '*.html' | foreach {
- $i+=1
- $j=[math]::ceiling($i/2000)
- $urls[$j] = $urls[$j] + $url -f $_.Name
- }n
-
- for ($x=1 ; $x -le [math]::ceiling($n/2000) ; $x++) {
- $xml -f $urls[$x] | Out-File "test$x.xml"
- }
复制代码
替换 21行到最后
[math]::ceiling 序号是 1 2 3
[math]::floor 序号是 0 1 2
作者: 任贤齐 时间: 2021-5-26 19:11
回复 3# newswan
感谢大神,你好像多写了个n 删除可以了 多谢多谢啊 像您学习
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |