Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Get-PWFolders Folderpath Case sensitivity
    • Sign In

    • State Not Answered
    • Replies 22 replies
    • Subscribers 68 subscribers
    • Views 2009 views
    • Users 0 members are here

    Get-PWFolders Folderpath Case sensitivity

    Robert Biggar
    Offline Robert Biggar over 2 years ago

    hey all:

    I am trying to figure out if a folder exists in ProjectWise.

    * attached to an Oracle Database.

    *Misc. / Force case-insensitive search - checked ON

    Location being searched for:

    "ProjectWise\Documents\-North Region\Alpena TSC\119813\1 - Base Plans\"

    -----------------------------------------------------------------------------------------------------

    $id = "alpena tsc\119813\1 - base plans"

    Returns:

    PS C:\PS> $project = Get-PWFolders -FolderPath $id -JustOne
    WARNING: 'alpena tsc\119813\1 - base plans' is not a valid folder name

    ----------------------------

    $id = "-North Region\Alpena TSC\119813\1 - Base Plans"

    PS C:\PS> Get-PWFolders -FolderPath $id -JustOne


    ProjectID : 589415
    Name : 1 - Base Plans
    Description : 1 - Base Plans
    FullPath : -North Region\Alpena TSC\119813\1 - Base Plans
    FolderDepth : 4 ...

    The lists of folders are not always as consistent as one would hope...

    any Ideas how to force the search for a folder to be case-insensitive?

     - I do not have the same trouble with the filename...only folder

    and I have seen the same behavior in "Get-PWFolders" and "Get-PWDocumentsBySearch" (-FolderPath) - so there is consistency!  :-D

    Thanks!

    Bob

    • Sign in to reply
    • Cancel

    Top Replies

    • Brandon Williams
      Offline Brandon Williams Tue, Jun 8 2021 10:42 AM +1
      In your first example, you are missing the parent folder. $id = "alpena tsc\119813\1 - base plans" vs $id = "-north region\alpena tsc\119813\1 - base plans" Are we sure this is a case sensitive…
    Parents
    • Brandon Williams
      0 Offline Brandon Williams Tue, Jun 8 2021 10:42 AM

      In your first example, you are missing the parent folder.

      $id = "alpena tsc\119813\1 - base plans"

      vs

      $id = "-north region\alpena tsc\119813\1 - base plans"

      Are we sure this is a case sensitive issue? My first thought is you are getting an error because you are missing part of the path.

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Robert Biggar
      0 Offline Robert Biggar Tue, Jun 8 2021 10:52 AM in reply to Brandon Williams

      That would be an easy fix, however the only change between the "first example" and the "second example" is case. I did try that though...

      PS C:\PS> $id = "documents\-alpena tsc\119813\1 - base plans"

      PS C:\PS> Get-PWFolders -FolderPath $id -JustOne
      WARNING: 'documents\-alpena tsc\119813\1 - base plans' is not a valid folder name

      ====================(With Root and the case change):

      PS C:\PS> $id = "Documents\-North Region\Alpena TSC\119813\1 - Base Plans"

      PS C:\PS> Get-PWFolders -FolderPath $id -JustOne
      WARNING: 'Documents\-North Region\Alpena TSC\119813\1 - Base Plans' is not a valid folder name

      =====================(No Luck)

      However without "the root" but with the case changes:

      PS C:\PS> $id = "-North Region\Alpena TSC\119813\1 - Base Plans"

      PS C:\PS> Get-PWFolders -FolderPath $id -JustOne


      ProjectID : 589415
      Name : 1 - Base Plans
      Description : 1 - Base Plans
      FullPath : -North Region\Alpena TSC\119813\1 - Base Plans
      FolderDepth : 4

      seems to work...

      Thanks.

      If you see anything I missed, or have another thought, ...I am all about trying! (only a fool is "positive"  :-)  )

      Thanks Brandon!

      Bob

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Wed, Jun 9 2021 9:35 AM in reply to Brian Flaherty

      Ah nice. I didn't realize you could trim on any character I normally only use it for white space. Turns out I can do the replace before the trim and do the entire thing in one go.

      Also realized I was doing a few too many comparisons with both the -contains test and the where extraction. So I just do the where and test if that succeeded.

      And finally removed that spurious $I = 0, which I know I was going to use as an loop counter but totally forget why I wanted one, and never used it.

      Final version gets down to 13 seconds (but this is running this morning with users on the system vs. last night so might be faster)

      $FindPath = "Top Folder\Sub-Folder 1\Another Sub\Way\Deep\In\The\Weeds\"
      
      # 1. Fix paths that have slashes instead of backslashes
      # 2. Trim leading and trailing backslashes
      # 3. Make each folder name an array entry
      $PathArray = $FindPath.Replace('/','\').Trim('\').Split('\')
      
      # Each element of FoundPath will be a hash:
      # @{
      #	'Name'
      #	'ProjectID'
      # }
      $FoundPath = @()
      
      # Get the folders at the top level
      $SubFolders = Get-PWFoldersImmediateChildren -Root
      ForEach ($fname in $PathArray) {
      	# is the current path in the $SubFolder list of names?
      	$matchFolder = $SubFolders | Where Name -eq $fname
      	if ($null -ne $matchFolder) {
      		$FoundPath += @{
      			'Name' = $matchFolder.Name
      			'ProjectID' = $matchFolder.ProjectID
      		}
      		$SubFolders = Get-PWFoldersImmediateChildren -FolderID $matchFolder.ProjectID -WarningAction SilentlyContinue
      	} else {
      		Throw "Folder not found. Path found up to $(($FoundPath.Name) -Join '\')"
      	}
      }
      
      $FinalPath = ($FoundPath.Name) -Join '\'
      $FinalID = $FoundPath[-1].ProjectID
      
      $FolderObj = Get-PWFolders -FolderID $FinalID -JustOne
      
      Write-Host "Found: [Folder ID: $($FinalID)] $($FinalPath)"
      

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Wed, Jun 9 2021 9:55 AM in reply to Kevin van Haaren

      This will fail if there are no folders in the root (or whoever runs it doesn't have access to the folders in root). Not gonna fix.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Robert Biggar
      0 Offline Robert Biggar Wed, Jun 9 2021 10:09 AM in reply to Kevin van Haaren

      very nice. very "Kernighan and Ritchie"  hah! dated myself there!  I am opting for a function that returns 0 or the found ID...I'm not sure how fast it will be but even if I have to run it over the weekend...it's going to be great!  Thanks Kevin and Brian....still intrigued by Dan's  suggestion ...a CMDLet written in Powershell. This "Exercise" is a good example of the infinite number of "tips, tricks, and even style variations"  that are out there.

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Robert Biggar
      0 Offline Robert Biggar Wed, Jun 9 2021 2:21 PM in reply to Robert Biggar

      Success. The code you provided that I put into a Function is working great...not fast, but "automated", and that works for me. the fact that "Contains" is case insensitive is the key. I'd share the function, but it is nearly the same as the above code. Thanks again!

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Wed, Jun 9 2021 3:34 PM in reply to Robert Biggar

      Yeah, that and storing the matched name rather than the searched name so the final path does come out with the correct casing on the path.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Kevin van Haaren
      0 Offline Kevin van Haaren Wed, Jun 9 2021 3:34 PM in reply to Robert Biggar

      Yeah, that and storing the matched name rather than the searched name so the final path does come out with the correct casing on the path.

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    No Data

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies