logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

xsquared_uk
#1 Posted : Friday, October 12, 2012 6:00:09 AM(UTC)
xsquared_uk

Rank: Newbie

Reputation:

Groups: Member
Joined: 10/5/2012(UTC)
Posts: 3

Hi all,

Is there any way to check that a folder exists using the PowerShell snapin?

I have a script which runs OK EXCEPT if the folder already exists, because it tries to create it again. I can't work out how to check if it exists, I know you can use test-path in PowerShell but I can't do this with the plugin.

Here is an example of the line of the script I need to change:

$newfolder = Get-Date -uformat "%Y-%m"
$target = $s3 | Select-CloudFolder -Path 'backup/backupfiles' | Add-CloudFolder $newfolder

I need to change it to something like:

if (!(test-file 'backup/backupfiles/$newfolder))
{
$target = $s3 | Select-CloudFolder -Path 'backup/backupfiles' | Add-CloudFolder $newfolder
}
else
{
$target = $s3 | Select-CloudFolder -Path 'backup/backupfiles/$newfolder'
}

Obviously that doesn't work but hopefully you can see what I'm trying to do.

Can anyone help?
fr3sh
#2 Posted : Tuesday, June 18, 2013 2:58:44 PM(UTC)
fr3sh

Rank: Newbie

Reputation:

Groups: Member
Joined: 6/18/2013(UTC)
Posts: 1

I had the same issue, found out the solution myself so I'm posting it here in case it helps someone.
OP wasn't too far off, but you must use Get-CloudItem to return the list of folders.

Code:

$newfolder = Get-Date -uformat "%Y-%m"

$dirlist = $s3 | Get-CloudRootFolder | Get-CloudItem

if ( ( $dirlist | Where-Object { $_ . displayName -like $newfolder } ).count -ge 1 ) {
   $destination = $s3 | Select-CloudFolder -path "backup/ $newfolder"
} else {
   $destination = $s3 | Select-CloudFolder -path "backup" | Add-CloudFolder $newfolder
}

Edited by user Tuesday, June 18, 2013 3:00:01 PM(UTC)  | Reason: Not specified

Guest
#3 Posted : Sunday, March 02, 2014 2:16:11 AM(UTC)
Rank: Guest

Groups: Guest

Message was deleted by a Moderator. | Reason: Not specified
Guest
#4 Posted : Sunday, March 02, 2014 11:55:23 AM(UTC)
Rank: Guest

Groups: Guest

Message was deleted by a Moderator. | Reason: Not specified
Guest
#5 Posted : Sunday, March 02, 2014 6:06:16 PM(UTC)
Rank: Guest

Groups: Guest

Message was deleted by a Moderator. | Reason: Not specified
Guest
#6 Posted : Sunday, March 02, 2014 8:13:38 PM(UTC)
Rank: Guest

Groups: Guest

Message was deleted by a Moderator. | Reason: Not specified
Guest
#7 Posted : Sunday, March 02, 2014 11:36:56 PM(UTC)
Rank: Guest

Groups: Guest

Message was deleted by a Moderator. | Reason: Not specified
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.6.1 | YAF © 2003-2014, Yet Another Forum.NET
This page was generated in 0.102 seconds.