Get drive-path-name of a file without extention

hi, I have this script

Function Format-FileSize() {
Param ([int]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {""}
}

$file=$args[0]
$size=Format-FileSize((Get-Item $file).length)
Write-Host($size) 
echo $size > test.txt
pause

the problem is: I like to replace “text.txt”(above the last line in program) with drive+path+name+txt extention
is there any google keyword, link, tips, function, or anything else to do this?
thank you

Hello kucing,

You want create a file with drive+path+name+txt like c:\temp\test1.txt?
that is impossible. because windows file name can’t contain these chars /:*?<>|
but this is possile
c+temp+test1+extention.txt

thank you Chen.Chen for the reply,
if input ‘c:\temp\test1.jpg’ the result will be saved in folder ‘c:\temp\’ with filename ‘test1’ and the extension is ‘.txt’
Is the PowerShell impossible to do this?

That’s very simple.

with your code.

$file=$args[0]
$path=Get-Item $file |Select-Object -ExpandProperty DirectoryName
$filename=Get-Item $file|Select-Object -ExpandProperty BaseName
Format-FileSize((Get-Item $file).length) | Out-File "$path\$filename.txt"

thank you again Chen.Chen for the reply,
the code you provide is works