# Get drive-path-name of a file without extention

**URL:** <https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788>\
**Category:** PowerShell Help\
**Created:** [October 20, 2021, 1:43am UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788 "2021-10-20T01:43:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kucingkucing](https://avatars.discourse-cdn.com/v4/letter/k/6a8cbe/32.png) [@kucingkucing](https://forums.powershell.org/u/kucingkucing)\
**Post date:** [October 20, 2021, 1:43am UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788/1 "2021-10-20T01:43:49Z")

</div>

hi, I have this script

```auto
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

---

<div class="post-metadata">

**Author:** ![Chen.Chen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/chen.chen/32/1689_2.png) [@Chen.Chen](https://forums.powershell.org/u/Chen.Chen)\
**Post date:** [October 20, 2021, 3:25am UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788/2 "2021-10-20T03:25:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kucingkucing](https://avatars.discourse-cdn.com/v4/letter/k/6a8cbe/32.png) [@kucingkucing](https://forums.powershell.org/u/kucingkucing)\
**Post date:** [October 20, 2021, 11:43am UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788/3 "2021-10-20T11:43:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chen.Chen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/chen.chen/32/1689_2.png) [@Chen.Chen](https://forums.powershell.org/u/Chen.Chen)\
**Post date:** [October 20, 2021, 1:08pm UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788/4 "2021-10-20T13:08:41Z")

</div>

That’s very simple.

with your code.

```auto
$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"

```

---

<div class="post-metadata">

**Author:** ![kucingkucing](https://avatars.discourse-cdn.com/v4/letter/k/6a8cbe/32.png) [@kucingkucing](https://forums.powershell.org/u/kucingkucing)\
**Post date:** [October 20, 2021, 1:44pm UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788/5 "2021-10-20T13:44:59Z")

</div>

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

---

<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:20pm UTC](https://forums.powershell.org/t/get-drive-path-name-of-a-file-without-extention/17788/6 "2024-05-16T20:20:37Z")

</div>

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


