2011-02-02 96 views
1

我想使用Test-Path和Resolve-Path来测试文件共享上是否存在子文件夹。首先我在我的机器\ someshare \ somefolder上创建一个共享。然后使用文件浏览器我添加子文件夹,以便整个路径是这样的:\ someshare \ somefolder \子文件夹测试使用子文件夹的UNC路径

Test-Path \\server\someshare results in True 
Test-Path \\server\someshare\subfolder results in False 


Resolve-Path \\server\someshare results in True 
Revolve-Path \\server\someshare\subfolder results in does not exist error 

为什么PowerShell不要在子文件夹返回true?

+0

难道是权限问题? – zdan 2011-02-02 23:04:22

回答

1

这里没有问题,听起来像权限,尝试连接为管理员?

& "net" "use" "\\192.168.1.1\psinstall" "password" "/USER:domain\username" 
Test-Path "\\192.168.1.1\psinstall\app" 
Test-Path "\\192.168.1.1\psinstall\app\subfolder" 
Resolve-Path "\\192.168.1.1\psinstall\app" 
Resolve-Path "\\192.168.1.1\psinstall\app\subfolder" 
& "net" "use" "\\192.168.1.1\psinstall" "/delete" 

& "net" "use" "\\192.168.1.1\c$\psinstall" "password" "/USER:domain\username" 
Test-Path "\\192.168.1.1\c$\psinstall\app" 
Test-Path "\\192.168.1.1\c$\psinstall\app\subfolder" 
Resolve-Path "\\192.168.1.1\c$\psinstall\app" 
Resolve-Path "\\192.168.1.1\c$\psinstall\app\subfolder" 
& "net" "use" "\\192.168.1.1\c$\psinstall" "/delete" 
1

我不能重新创建你所说的结果,但我会注意到你所提供的UNC似乎是关闭的。 UNC通常是\ server \ share \文件夹。您似乎已经省略了服务器名称。网络上实际上是否有机会与共享中使用的名称相同,这就是您正在测试的内容?

更新:你说你已经创建了\ server \ someshare \ somefolder,然后将\ subfolder添加到路径中。您正在测试\ server \ someshare \子文件夹。假设您对文件夹创建的描述是准确的,则表明您应该测试\ server \ someshare \ somefolder \子文件夹。

+0

你是正确的,但问题仍然非常有规律。我将编辑我的原始帖子。感谢您的期待。 – ChiliYago 2011-02-02 22:33:32