Can anybody show me how to split windows path on folders, file and drive ?
Do I need regex ?
Can anybody show me how to split windows path on folders, file and drive
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
RegExp? Yes and No – you can use
String#splitwhich uses a regular expression even though it often feels like using a normal String:This results in drive (
parts[0]), folders (parts[1]andparts[2]) and filename (parts[parts.length-1])You may have to test if the first segment is a drive name (ends with “:”), the last segment is a file name (
file.isDirectory()) and if a segment contains a folder (like no folder inC:\test.txt.