Cannot find drive. A drive with the name '"C' does not existeee

Kindly assist please, this code is report error, in light of the space around C. I thought it wihit space created by the .ToString.

Blockquote

function Set-ArchivePath{
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory=$true)]
        [string]$ZipPath,

        [Parameter(Mandatory=$true)]
        [string]$ZipPrefix,

        [Parameter(Mandatory=$true)]
        [datetime]$Date
    )
    if(-not(Test-Path -Path $ZipPath)){
        New-Item -Path $ZipPath -ItemType Directory | Out-Null
        Write-Verbose "Creating Directory '$ZipPath'"
    }$TimeString = $Date.ToString('yyyyMMdd')
    $ZipName = "$($ZipPrefix)$($TimeString).zip"
    $fileName = (Join-Path $ZipPath $ZipName)
I have attached the code, the output is below

New-Item:
Line |
  15 |          New-Item -Path $ZipPath -ItemType Directory | Out-Null
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find drive. A drive with the name '"C' does not exist.
Join-Path:
Line |
  19 |      $fileName = (Join-Path $ZipPath $ZipName)
     |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find drive. A drive with the name '"C' does not exist.
Test-Path:
Line |
  21 |      if(Test-Path -Path $fileName){
     |         ~~~~~~~~~~~~~~~~~~~~~~~~~

John

could you please go back, edit your question once again and fix the formatting of your code?

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Your code seem to be incomplete. And how exactly did you you call the function? What values did you provide it?

Thanks for reaching out Olaf

I have done as directed.

Thank you
I figured it out now

I was passing the path as a string
I just need to correct that and it was fine

Great to hear you’ve found the solution yourself. :+1:t3: