Forum Discussion
phantom2000
Jan 04, 2022Copper Contributor
Get file name from FTP Server
Hello, I am using below code to query an FTP folder and get the name of the existing file. However, I am not getting the desired output. I get some unwanted results from the code. I appreciate s...
SteveMacNZ
Jan 17, 2022Iron Contributor
you could also try using split as well to split out the filename from the path. I use the below script in my scripts to create a batch name using the filename without the extension
$BatchNameTemp = $Script:File.split("\")[-1]
$Script:BatchName = $BatchNameTemp.substring(0,($BatchNameTemp.length-4))
so you could modify your script to
$FName = $list.split("/")[-1]
Jonathan_Allen
Feb 04, 2022Brass Contributor
It's well worth using split-path to separate files names and file paths..
# to get the file name
split-path "C:\windows\system32\notepad.exe" -Leaf
# result
# notepad.exe
# to get the directory
split-path "C:\windows\system32\notepad.exe" -Parent
# result
# C:\windows\system32