PowerShell脚本用_替换特殊字符 [英] PowerShell Script Replace Special Characters with _

查看:140
本文介绍了PowerShell脚本用_替换特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想使用/开发一个脚本,以便可以替换特殊字符,例如〜" #%& *:< > ? /\ {| }.从我的根文件夹开始的每个文件夹中的文件名中.

I would like to use/develop a script with that I can replace the special characters such as ~ " # % & * : < > ? / \ { | }. in file names in every folder starting from my root folder.

我尝试了此脚本,但无法正常工作.

I tried this script, but it is not working properly.

我希望你能帮助我开发这个.

I hope you can help me to develop this.

$ AR = @ {"1" ="*〜*";"2" ="*""*";"3" ="*#*";"4" ="*%*";"5" ="*& *";"6" ="*?*";"7" ="*/*"}

Get-ChildItem-递归-包括" $ AR.getenumerator()| %{$ _.value}"  |选择对象名称,目录|导出Csv C:\ Users \ username \ Documents \ export.csv

$AR = @{"1"="*~*";"2"="*""*";"3"="*#*";"4"="*%*";"5"="*&*";"6"="*?*";"7"="*/*"}

Get-ChildItem -Recurse -Include "$AR.getenumerator() | % { $_.value }"  | Select-Object Name,Directory | Export-Csv C:\Users\username\Documents\export.csv

当我在文件夹上运行此脚本时,会得到一个空的excel工作表,但是我知道它应该包含值.

When I run this script on the folder I get an empty excel sheet, but I know this should contain values.

这是我到目前为止开发的.

this is what I've developed so far.

最诚挚的问候

Matthias

推荐答案

你好,

您应该将目录内容获取到一个数组中,然后对其进行解析,并在需要时生成新名称并进行更新.像这样的东西:

you should grab the directory content to an array, then parse it, generate new name when needed and update it. Something like this :


arDIR = get-childitem"c:\ test";递归| ? {
arDIR = get-childitem "c:\test" -recurse | ? {


_.PSisContainer -eq
_.PSisContainer -eq


这篇关于PowerShell脚本用_替换特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆