English 中文(简体)
重新命名档案以删除权力领域的期限
原标题:Renaming files to remove periods in Powershell

I have a list of files like this:
Test.(file1)[text].txt
Test.(file2)[text].txt
Test.(file3)[text].txt

我需要删除任何“()”、“[]”和任何“......”,在不改变档案延期的情况下替换这些空间。 我曾尝试过以下工作,但没有工作:

dir C:scratch*.txt | % { Rename-Item $_ ($_.basename -replace "(", " "`
            -replace ")", " "`
            -replace "[", " "`
            -replace "]", " "`
            -replace ".", " ")}

理想的情况是,档案名称应当以“试验文件1文本.txt”的形式结束。

最佳回答

海事组织 Rename-Item似乎是在用[ ]果园处理道路上发生的。 幸运的是,Move-Item工程:

dir *.txt | 
    mi -dest {($_.Basename -replace  [()[].]+ ,   ).Trim() + $_.Extension}

http://www.ohchr.org。 请注意,诸如Rename-Item和Move-Item等一些圆柱可直接投管,然后其新Name/混凝土参数可使用管束弹。 从内部来看,由于PowerShell公司,这一管道约束参数的工程将执行锁,并试图将结果强制到参数预期的类型。

问题回答




相关问题
How can I load a folders files into a ListView?

I d like to have a user select a folder with the FolderBrowserDialog and have the files loaded into the ListView. My intention is to make a little playlist of sorts so I have to modify a couple of ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Saving output of a for-loop to file

I have opened a file with blast results and printed out the hits in fasta format to the screen. The code looks like this: result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast ...

热门标签