New-Item -itemtype directory is making a file not a directory

$path = dir env:userprofile
[Int]$FileCount = 0
[Boolean]$AllFilesFound = $false
[Int]$Sleep10Secs = 10
[Int]$NumOfFiles = 0
[INT]$seconds = 10
function movefiles { move-item ($ListOfFiles) -destination .$getdate }
function makedir { new-item -name .$getdate -itemtype directory -path h:\testdir\test }

#Sets the current working location
Set-Location “h:\Testdir\test”

while ($AllFilesFound -eq $false)
{
cls

Write-Host "Searching for files."
$ListOfFiles = Get-ChildItem | where {!$_.PsIsContainer}

foreach ($item in $ListOfFiles)
{
$NumOfFiles++
}

if($NumOfFiles -ge 5)
{
Write-Host “nFound $NumOfFiles files!!!" $getdate = get-date -format yyyymmddhmmss Write-host $listoffiles Add-Content -value $NumOfFiles -path h:\Testdir\Archive.log movefiles makedir $NumOfFiles = 0 Write-Host "nExiting Program.`n”
}

for($timer=$seconds;$timer -gt 1; $timer–)
{
$perComplete = 100-($timer * 10)

Write-Progress -Activity "Searching for Files..." -Secondsremaining $Timer -PercentComplete $percomplete -status "Please Wait..." 
start-sleep 1

}

}

New-Item -ItemType Container -Name deleteme

New-Item is probably failing altogether. You’re calling “MoveFiles” before “MakeDir”. By the time you get to calling New-Item, there’s already a file with the name of the directory you’re trying to create.

If you call MakeDir before MoveFiles, it will probably work.

thanks Dave. That fixed it. I appreciate the help