将 setCaseSensitiveInfo 递归应用于所有文件夹和子文件夹

编程入门 行业动态 更新时间:2024-10-27 15:24:42
本文介绍了将 setCaseSensitiveInfo 递归应用于所有文件夹和子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将我的 dotnet 核心项目(在 Windows 中)配置为区分大小写",因此它的行为与我的生产服务器 (linux) 中的一样.

我有找到这种方式 这样做:

fsutil.exe 文件 setCaseSensitiveInfo "C:\my folder" enable

问题是这个函数不是递归的:

区分大小写标志仅影响您应用它的特定文件夹.该文件夹的子文件夹不会自动继承它.

所以我正在尝试构建一个 powershell 脚本,以递归方式将其应用于所有文件夹和子文件夹.

我试过用谷歌搜索类似的东西,只是修改命令行,但我似乎没有找到正确的关键字.这是 最接近的我已经看到了这种例子.

解决方案

正确代码:

(Get-ChildItem -Recurse -Directory).FullName |ForEach-Object {fsutil.exe 文件 setCaseSensitiveInfo $_ enable}

说明:

注意:答案中的代码假定您位于目录树的根目录中,并且您希望针对其中的所有文件夹运行 fsutil.exe,如已在评论中指出(感谢 @Abhishek Anand!)

Get-ChildItem -Recurse -Directory 将为您提供所有文件夹的列表(递归).

如果你想传递他们的完整路径,你可以使用 .FullName[1](或者更不言自明的 | Select-Object-ExpandProperty FullName).

然后您使用 ForEach-Object 多次运行 fsutil.exe.当前文件的FullName 可以使用$_ 访问(这代表ForEach-Object 中的当前对象)[2].

提示:

如果您想更多地跟踪当前正在处理的内容,您可以添加以下内容以将当前处理的文件的路径写入控制台:;Write-Host $_(分号 ; 与 fsutil 调用分开)正如评论中指出的那样(感谢 资助莫妮卡的诉讼!)

[1] .FullName 表示法适用于 PowerShell 3.0 及更高版本,Select-Object -ExpandProperty FullName 是首选,如果较低版本有可能使用.

[2] $_ 是 $PSItem

的别名

I am trying to configure my dotnet core project (in Windows) as "case sensitive", so it behaves as in my production server (linux).

I have found this way of doing it:

fsutil.exe file setCaseSensitiveInfo "C:\my folder" enable

The problem is that this function is not recursive:

The case sensitivity flag only affects the specific folder to which you apply it. It isn’t automatically inherited by that folder’s subfolders.

So I am trying to build a powershell script that applies this to all folders and subfolders, recursively.

I have tried googling something similar and just modifying the command line, but I don't seem to find the corrent keywords. This is the closest that I've gotten to this sort of example.

解决方案

Correct code:

(Get-ChildItem -Recurse -Directory).FullName | ForEach-Object {fsutil.exe file setCaseSensitiveInfo $_ enable}

Explanation:

NOTE: The code in the answer assumes you're in the root of the directory tree and you want to run fsutil.exe against all the folders inside, as it's been pointed out in the comments (thanks @Abhishek Anand!)

Get-ChildItem -Recurse -Directory will give you list of all folders (recursively).

As you want to pass their full path, you can access it by using .FullName[1] (or more self-explanatory | Select-Object -ExpandProperty FullName ).

Then you use ForEach-Object to run fsutil.exe multiple times. Current file's FullName can be accessed using $_ (this represents current object in ForEach-Object)[2].

Hint:

If you want more tracking of what's currently being processed you can add the following to write the path of currently processed file to the console: ; Write-Host $_ (semicolon ; is to separate from fsutil invocation) as it was pointed out in the comments (thanks Fund Monica's Lawsuit !)

[1] .FullName notation works for PowerShell 3.0 and greater, Select-Object -ExpandProperty FullName is preferred if there's a chance that lower version will be used.

[2] $_ is an alias for $PSItem

更多推荐

将 setCaseSensitiveInfo 递归应用于所有文件夹和子文件夹

本文发布于:2023-11-12 17:04:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   文件夹   应用于   setCaseSensitiveInfo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!