# Case Sensitive Code Tweak

**URL:** <https://forums.powershell.org/t/case-sensitive-code-tweak/2085>\
**Category:** PowerShell Help\
**Created:** [November 19, 2013, 5:51am UTC](https://forums.powershell.org/t/case-sensitive-code-tweak/2085 "2013-11-19T05:51:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas-reaves-7](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@thomas-reaves-7](https://forums.powershell.org/u/thomas-reaves-7)\
**Post date:** [November 19, 2013, 5:51am UTC](https://forums.powershell.org/t/case-sensitive-code-tweak/2085/1 "2013-11-19T05:51:59Z")

</div>

I worked though this bit of code a while back and with the help of the folks around here, this has been one of the best tools I have ever had. Simply, this is a script that look at a file name and breaks it apart to file it in to separate locations. The only complaint I have had is it is case sensitive. My files are structured as “Job Name - Vendor Name - Acct Name - PO number”.pdf. If I Use “job name” instead of “Job Name” it creates two separate folders even though the capitals are the only difference. I would really like for this script to be a little less picky about that. Code Follows and Thank you for the help.

```
Get-ChildItem -path "C:\Users\treaves\Documents" -Filter *.pdf | foreach {
  #saving the $_ is unnecessary but makes the example more readable
   $currentFile = $_
   #split the values
   $Community,$vendor,$work,$po = $CurrentFile.basename -split "-" | foreach {$_.Trim()}
  #This is where my code begins
  #This should create a vendor folder
  $Vendordestination = Join-Path -Path "P:\SyncFolder\Dropbox\Vendor Files" -ChildPath $Vendor
  #if the destination folder does not exist create it
 if (-not (Test-Path $Vendordestination))
  {
       New-Item -Path $Vendordestination -ItemType "directory" -Force
    }
#Hopefully this will copy the file based on the vendor
Copy-Item -Path $currentFile.fullname -Destination $Vendordestination -Force    
  #create the path to make working with it easy and error proof
   $Cmtdestination = Join-Path -Path "P:\SyncFolder\Dropbox\Builder Folder" -ChildPath $Community
  #if the destination folder does not exist create it
 if (-not (Test-Path $Cmtdestination))
  {
       New-Item -Path $Cmtdestination -ItemType "directory" -Force
    }
   #add force to rewrite files in the destination folder 
  Move-Item -Path $currentFile.fullname -Destination $Cmtdestination -Force
  #add second test path, destination and move here to move to another location.
}
```

```
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 19, 2013, 6:04am UTC](https://forums.powershell.org/t/case-sensitive-code-tweak/2085/2 "2013-11-19T06:04:39Z")

</div>

Are you positive that the case of the letters is the only difference? The FileSystem provider that’s handling those paths in Test-Path and New-Item is not case sensitive; it shouldn’t be behaving the way you’re describing. For example:

```
$Path = Join-Path -Path $env:temp -ChildPath 'SomeNewFolderName'

Test-Path $Path # False

$null = New-Item -Path $Path -ItemType Directory

Test-Path $Path # True

$Path = $Path.ToLower()
$Path

Test-Path $Path # True

New-Item -Path $Path -ItemType Directory # Throws an error because the item already exists
```

---

<div class="post-metadata">

**Author:** ![thomas-reaves-7](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@thomas-reaves-7](https://forums.powershell.org/u/thomas-reaves-7)\
**Post date:** [November 19, 2013, 6:12am UTC](https://forums.powershell.org/t/case-sensitive-code-tweak/2085/3 "2013-11-19T06:12:30Z")

</div>

Completely Certain. I create the PDF from an excel script every time. I have worked around it by setting up tables to look up the exact same name in most cases, but when I have a vendor that is not on that list and it does not auto populate it, If I do not type the name exactly including case, it will make new folders. 90% of the time, its not a problem, which is great, but the other 10% of the time is nearly impossible to notice until I am trying to track it down.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 19, 2013, 6:51am UTC](https://forums.powershell.org/t/case-sensitive-code-tweak/2085/4 "2013-11-19T06:51:09Z")

</div>

Fair enough. I can’t explain why it’s giving you this problem, but if we throw out the assumption that the file system is not supposed to be case sensitive, you could try this:

```
$textInfo = [System.Globalization.CultureInfo]::CurrentCulture.TextInfo

Get-ChildItem -path "C:\Users\treaves\Documents" -Filter *.pdf | foreach {
    $currentFile = $_
    $Community,$vendor,$work,$po = $CurrentFile.basename -split "-" | foreach { $textInfo.ToTitleCase($_.Trim()) }
    
    # ...
}
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/case-sensitive-code-tweak/2085/5 "2024-05-16T20:52:35Z")

</div>

Closed on May 16, 2024, 8:52pm UTC


