【发布时间】:2018-04-28 17:42:04
【问题描述】:
我有一个文本文件,其中包含不同目录中的文件列表,例如
C:\FolderOne\Testing.jpgC:\FolderTwo\Test.jpg
我想把这些名字变成文件夹。如果两个文件存在于一个文件夹中,例如FolderOne,那么这两个文件都应该放在同一个文件夹中。
我知道反斜杠也必须替换为下划线,冒号也必须替换为下划线。
到目前为止,我能够从文件列表中获取内容并将其复制到指定的文件夹中。我想为文件列表中的每个文件创建一个文件夹,但是文件夹名称需要包括C_FolderOne和C_FolderTwo等等....
任何帮助将不胜感激!
到目前为止我所拥有的:
Param (
[String]$model
)
# Debug line
$model = "DEV2";
[String]$drive = "C:";
#Go to the PG_dump directory
CD "C:\Program Files\PostgreSQL\9.4\bin"
##Execute PG_dump with no password
.\pg_dump.exe --host localhost --port 5432 --username "postgres" --role "postgres" --no-password --format custom --blobs --verbose --file "C:\Test\$date-DEV-$X.backup" "DEV"
#Get the content from the file list
$file_list = Get-Content "$drive\Testing\DEV33.txt"
foreach ($file in $file_list)
{
Copy-Item $file -Destination "C:\Testing"
}
【问题讨论】:
-
您的问题不清楚。你到底想做什么?
-
在“work”文件夹下创建的路径(例如 - “C:\Testing”)是否包含多个段(例如 - C:\Folder A\Folder A - Sub Folder 0\ ...\filename.jpg")?
-
@TheIncorrigible1 基本上,尝试为文件列表中的每个文件创建一个文件夹。创建的文件夹应以文件夹的路径命名,例如,如果名为“Winter.jpg”的文件位于“C:\TestFolder\Winter.jpg”,则应创建名为 C_TestFolder 的文件夹。
-
@codemaker 你好,是的,在“work”文件夹下创建的路径可以包含多个段。
-
(Split-Path -Path $Path -Parent) -replace ':\\','_'@TheManBehindTheMan 制定逻辑以捕获 `\\` 的其余部分
标签: windows powershell scripting directory copy-item