I want to extract the only path to the file from a full path.
for %a in (/path/to/file/filename.txt) do echo %%~dpa
example:
/some/path/to/file/filename.txt
I want to get the only path like
/some/path/to/file/
I want to extract the only path to the file from a full path.
for %a in (/path/to/file/filename.txt) do echo %%~dpa
example:
/some/path/to/file/filename.txt
I want to get the only path like
/some/path/to/file/
Maybe this would do the trick for you:
x=/path/to/file/filename.txt
y=${x%\/*}
echo $y
you should get
/path/to/file
You can use string operations to parse the file_name
out (https://stackoverflow.com/a/3162500).
Delete the shortest matching file_name
from the end of full_path
using %
operator.
full_path=/path/to/file/filename.txt
file_name=${full_path##*/}
echo "${full_path%$file_name}"
Replace full_path
with your desired input and it will return /path/to/file/