找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: 5i365

[问题求助] PowerShell有条件地给某个文件夹中所有子文件夹分配指定数量的文件夹

[复制链接]
 楼主| 发表于 2022-1-11 14:50:19 | 显示全部楼层
回复 15# idwma


    Index operation failed; the array index evaluated to null.
At line:4 char:70
+ ... lname + '\ok')") { while ($j++ -lt $k) { if ($a[$i] -ne $null){move $ ...
+                                                  ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ( [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:4 char:70
+ ... lname + '\ok')") { while ($j++ -lt $k) { if ($a[$i] -ne $null){move $ ...
+                                                  ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:4 char:70
+ ... lname + '\ok')") { while ($j++ -lt $k) { if ($a[$i] -ne $null){move $ ...
+                                                  ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:4 char:70
+ ... lname + '\ok')") { while ($j++ -lt $k) { if ($a[$i] -ne $null){move $ ...
+                                                  ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:4 char:70
+ ... lname + '\ok')") { while ($j++ -lt $k) { if ($a[$i] -ne $null){move $ ...
+                                                  ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At line:4 char:70
+ ... lname + '\ok')") { while ($j++ -lt $k) { if ($a[$i] -ne $null){move $ ...
+                                                  ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

请按任意键继续. . .
发表于 2022-1-11 15:07:09 | 显示全部楼层
回复 16# 5i365
  1. #&cls&@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &pause&exit
  2. $k = 2
  3. Get-ChildItem ".\A" -Directory | Sort-Object { [int]($_.Name -split '\s+')[0] } | foreach-Object { [array]$a += $_.FullName }
  4. dir .\b | ?{ $_.PSIsContainer } | %{
  5.         if (test-path "$($_.fullname + '\ok')") { while ($j++ -lt $k) { if ($a[$i++] -ne $null){move $a[$i-1] $_.fullname} } }
  6. $j=$null
  7. }
  8. if ($a[++$i] -eq $null) { "分完" }
复制代码
 楼主| 发表于 2022-1-11 15:40:05 | 显示全部楼层
回复 17# idwma


    可以分了, 但是新问题来了,  A里7个文件夹, B里有三个, 执行脚本后, B里每个文件夹分到了A里的两个文件夹, 但此时我再次执行脚本, 却又把A余下的1个分给了B里的第一个文件夹, 但, 此时并不满足条件, 因为它里面已经分到两个文件夹了, 并不是只有一个OK文件夹
发表于 2022-1-11 16:20:40 | 显示全部楼层
回复 18# 5i365
  1. #&cls&@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &pause&exit
  2. $k = 2
  3. Get-ChildItem ".\A" -Directory | Sort-Object { [int]($_.Name -split '\s+')[0] } | foreach-Object { [array]$a += $_.FullName }
  4. dir .\b | ?{ $_.PSIsContainer } | %{
  5.         if ((test-path $($_.fullname + '\ok')) -and (dir $_.fullname).count -lt 1) { while ($j++ -lt $k) { if ($a[$i++] -ne $null){move $a[$i-1] $_.fullname} } }
  6. $j=$null
  7. }
  8. if ($a[++$i] -eq $null) { "分完" }
复制代码
 楼主| 发表于 2022-1-11 16:29:06 | 显示全部楼层
回复 19# idwma


    不报错, 也没有移动文件夹
发表于 2022-1-11 16:55:48 | 显示全部楼层
本帖最后由 idwma 于 2022-1-11 18:17 编辑

回复 20# 5i365


    这次测了是可以的
怕不是又是powershell版本问题,2.0dir只有一个时count的数不是1
  1. #&cls&@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &pause&exit
  2. $k = 2
  3. Get-ChildItem ".\A" -Directory | Sort-Object { [int]($_.Name -split '\s+')[0] } | foreach-Object { [array]$a += $_.FullName }
  4. dir .\b | ?{ $_.PSIsContainer } | %{
  5.         if ((test-path $_.fullname + '\ok')) -and $(dir $_.fullname|%{$n++};$n;$n=$null) -lt 2) { while ($j++ -lt $k) { if ($a[$i++] -ne $null){move $a[$i-1] $_.fullname} } }
  6. $j=$null
  7. }
  8. if ($a[++$i] -eq $null) { "分完" }
复制代码
 楼主| 发表于 2022-1-11 19:46:10 | 显示全部楼层
回复 21# idwma


    Invoke-Expression : At line:4 char:37
+     if ((test-path $_.fullname + '\ok')) -and $(dir $_.fullname|%{$n+ ...
+                                        ~
Missing statement block after if ( condition ).
At line:3 char:36
+ dir .\b | ?{ $_.PSIsContainer } | %{
+                                    ~
Missing closing '}' in statement block or type definition.
At line:4 char:88
+ ...  + '\ok')) -and $(dir $_.fullname|%{$n++};$n;$n=$null) -lt 2) { while ...
+                                                                 ~
Unexpected token ')' in expression or statement.
At line:6 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
At line:1 char:98
+ ... 歌曲文件夹 2.bat' | Select-Object -Skip 1 | Out-String | Invoke-Expression
+                                                         ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: ( [Invoke-Expression], ParseException
    + FullyQualifiedErrorId : MissingStatementBlock,Microsoft.PowerShell.Commands.InvokeExpressionCommand

请按任意键继续. . .
发表于 2022-1-11 21:50:47 | 显示全部楼层
回复 22# 5i365
  1. #&cls&@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &pause&exit
  2. $k = 2
  3. Get-ChildItem ".\A" -Directory | Sort-Object { [int]($_.Name -split '\s+')[0] } | foreach-Object { [array]$a += $_.FullName }
  4. dir .\b | ?{ $_.PSIsContainer } | %{
  5.         if ((test-path $($_.fullname + '\ok')) -and $(dir $_.fullname|%{$n++};$n;$n=$null) -lt 2) { while ($j++ -lt $k) { if ($a[$i++] -ne $null){move $a[$i-1] $_.fullname} } }
  6. $j=$null
  7. }
  8. if ($a[++$i] -eq $null) { "分完" }
复制代码

评分

参与人数 1技术 +1 收起 理由
5i365 + 1 感谢帮忙! 细心!耐心!

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 23:19 , Processed in 0.017246 second(s), 7 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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