简体   繁体   English

根据长度递归重命名文件夹

[英]Recursively rename folders based on length

I have thousands of files in thousands of directories. 我在数千个目录中有数千个文件。 Some of these paths are out of control and longer than what Windows can handle, so when I try to access the files within PowerShell, I get an error. 其中一些路径失控,并且超出Windows的处理范围,因此当我尝试在PowerShell中访问文件时,出现错误。 How can I rename folders within these paths if they contain a certain length of characters? 如果这些路径中包含一定长度的字符,我该如何重命名这些文件夹? (for example, like 50+ characters for one folder) (例如,对于一个文件夹,超过50个字符)

Edit: 编辑:

No, it is not Linux. 不,不是Linux。

Error: This is when I do a recursive searce to find all files on the server. 错误:这是在我进行递归搜索时发现服务器上的所有文件的时候。

Get-ChildItem : The specified path, file name, or both are too long. Get-ChildItem:指定的路径,文件名或两者都太长。 The fully qualified file name must be less than 26 0 characters, and the directory name must be less than 248 characters. 完全限定的文件名必须少于26 0个字符,目录名称必须少于248个字符。

使用subst将父文件夹映射到驱动器号,然后从那里继续。

After working with another person on the code, we were able to come up with something that works. 与另一个人一起编写代码后,我们提出了一些可行的方法。 I actually had to make the search length smaller because some of these paths were really out of control. 实际上,我不得不使搜索长度变小,因为其中某些路径确实失控了。

takeown /f \\server\share\foo /r /d Y /a >c:\takeown.log

$folders= Get-ChildItem -Path "\\server\share\foo" -recurse | where {$_.PsIsContainer}
$sortedfolders = $folders | sort-object -descending -property fullname
foreach ($f in $folders) {
if ($f.name.length -gt 10) { 

   rename-item $f.fullname (get-random).tostring()
   } 
}


$aolesfolders | gm

$sorted | ft fullname
$aolesfolders | select-object name, root, fullname, parent | export-csv     c:\testrename.txt
get-random | gm
(get-random).ToString().gettype()

foreach ($f in $folders) {
if ($f.name.length -gt 10) { 

   rename-item $f.fullname (get-random).tostring()
   } 
} 

{rename-item $f.name $f.parent+}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM