isnoend2001
asked on
Extract file name from path and maybe folder
I am trying to create a file backup to a usb drive using filecopy. The mainpath is where i need help. The file could be in a sub folder under app.path. The app.path looks like this:
mainPath =C:\Program Files\MyApp\Jo Blow 147 Elm Ave.bid or could be Something else like:
mainPath =C:\Program Files\MyApp\June Bids\Jo Blow 147 Elm Ave.bid in this case i want to copy the June Bids folder and the file name. How can i do this ?
mainPath =C:\Program Files\MyApp\Jo Blow 147 Elm Ave.bid or could be Something else like:
mainPath =C:\Program Files\MyApp\June Bids\Jo Blow 147 Elm Ave.bid in this case i want to copy the June Bids folder and the file name. How can i do this ?
Using API...
Private Declare Sub PathStripPathW Lib "shlwapi.dll" (ByVal pszPath As Long)
Public Function StripPath(ByVal szPath As String) As String
Call PathStripPathW(StrPtr(szPath))
StripPath = Left$(szPath, InStr(1, szPath, vbNullChar) - 1)
End Function
ASKER
Thanks egl1044
That works for giving just the file name, but need to determine if the file is in a sub folder and copy the folder name first. The file could be in a folder under App.path like: App.path & "June bids" and then the file name or:
App.path & "July bids" and then the file name or whatever. This is getting a little more involved than i thought. I guess what i need to do is find if there is a sub folder then make that folder on the flash then copy the file. How to determine if file is in a subfolder and get the folder name ?
That works for giving just the file name, but need to determine if the file is in a sub folder and copy the folder name first. The file could be in a folder under App.path like: App.path & "June bids" and then the file name or:
App.path & "July bids" and then the file name or whatever. This is getting a little more involved than i thought. I guess what i need to do is find if there is a sub folder then make that folder on the flash then copy the file. How to determine if file is in a subfolder and get the folder name ?
Remove the filename and keep the path using API
Private Declare Function PathRemoveFileSpecW Lib "shlwapi.dll" (ByVal pszPath As Long) As Boolean
Public Function RemoveFileSpec(ByVal szPath As String) As String
' * Removes the trailing file name and backslash from a path
Call PathRemoveFileSpecW(StrPtr(szPath))
RemoveFileSpec = Left$(szPath, InStr(1, szPath, vbNullChar) - 1)
End Function
ASKER
That does remove the file however how do i determine if the file is in a sub folder and get the folders name? It could be:
C:\Program Files\Myapp\Jo Blow 147 Elm Ave.bid or
C:\Program Files\Myapp\July Bids\Jo Blow 147 Elm Ave.bid or even
make a folder on flash drive
Then Mkdir FlashDriveLetter\Bidfileba ckups\July Bids
or even
C:\Program Files\Myapp\July Bids\Comp Shingles\Jo Blow 147 Elm Ave.bid
Then make 2 folders on flash drive
Then Mkdir FlashDriveLetter\Bidfileba ckups\July Bids
Then Mkdir FlashDriveLetter\Bidfileba ckups\July Bids\Comp Shingles
C:\Program Files\Myapp\Jo Blow 147 Elm Ave.bid or
C:\Program Files\Myapp\July Bids\Jo Blow 147 Elm Ave.bid or even
make a folder on flash drive
Then Mkdir FlashDriveLetter\Bidfileba
or even
C:\Program Files\Myapp\July Bids\Comp Shingles\Jo Blow 147 Elm Ave.bid
Then make 2 folders on flash drive
Then Mkdir FlashDriveLetter\Bidfileba
Then Mkdir FlashDriveLetter\Bidfileba
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have a routine that copies the whole structure, but there may be 100's of small files, just want to copy 1 file silently and fast. Guess i will ask another question more precise to what i need, thanks
Open in new window