Board logo

标题: [文件操作] [已解决]批处理怎样把数量超过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) 这样
请问各位大神如何修改?

一次性插入代码:
  1. @powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
  2. $xml = @'
  3. <?xml version="1.0" encoding="utf-8"?>
  4. <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">
  5.     <url>
  6.         <loc>http://www.baidu.com/</loc>
  7.         <changefreq>daily</changefreq>
  8.         <priority>1.00</priority>
  9.     </url>
  10.     {0}
  11. </urlset>
  12. '@
  13. $url = @'
  14.     <url>
  15.         <loc>http://www.baidu.com/{0}</loc>
  16.         <changefreq>daily</changefreq>
  17.         <priority>0.8</priority>
  18.     </url>
  19. '@
  20. $endl = "`r`n"
  21. $urls = ''
  22. Get-ChildItem '*.html' | foreach { $urls += $url -f $_.Name }
  23. $xml -f $urls | Out-File 'test.xml'
  24. 'test.xml'
复制代码

作者: 任贤齐    时间: 2021-5-24 23:26

不知道有大神知道吗 谢谢
作者: newswan    时间: 2021-5-26 11:37

本帖最后由 newswan 于 2021-5-26 12:59 编辑
  1. $endl = "`r`n"
  2. $urls = @()
  3. $n=(get-childitem *.html).count
  4. for ($x=0 ; $x -le $n ; $x++) {
  5.     $urls += ""
  6. }
  7. $i=0
  8. Get-ChildItem '*.html' | foreach {
  9.     $i+=1
  10.     $j=[math]::ceiling($i/2000)
  11.     $urls[$j] = $urls[$j] + $url -f $_.Name
  12. }n
  13. for ($x=1 ; $x -le [math]::ceiling($n/2000) ; $x++) {
  14.     $xml -f $urls[$x] | Out-File "test$x.xml"
  15. }
复制代码
替换 21行到最后

[math]::ceiling 序号是 1 2 3
[math]::floor 序号是 0 1 2
作者: 任贤齐    时间: 2021-5-26 19:11

回复 3# newswan


    感谢大神,你好像多写了个n 删除可以了 多谢多谢啊  像您学习




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2