Results 1 to 11 of 11

Thread: [RESOLVED] [help] how to delete file with unicode filepath

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Resolved [RESOLVED] [help] how to delete file with unicode filepath

    hey guys, i need ur help ...

    i've a file named

    D:\?-Tö+

    i want to delete it, but i didn't yet find how to solve this problem ...
    i can't use deletefile() or kill() function ...

    please, help me ..

    thanks for ur help ..

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [help] how to delete file with unicode filepath

    Welcome to the forums.

    Actually, you can use DeleteFile, but need to use the Unicode version: DeleteFileW
    Notice the parameter is different and so is how it is passed
    Code:
    Private Declare Function DeleteFileW Lib "kernel32.dll" (ByVal lpFileName As Long) As Long
    
    Sample call: lResult = DeleteFileW(StrPtr(sFileName))
    sFileName is a string that contains the unicode file name.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [help] how to delete file with unicode filepath

    Use the UniCode version of the API

    Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileW" (ByVal lpFileName As Long) As Long

    Then use stringPointer to point to the file.

    DeleteFile strPtr("D:\?-Tö+")
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Re: [help] how to delete file with unicode filepath

    Quote Originally Posted by some1uk03 View Post
    Use the UniCode version of the API

    Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileW" (ByVal lpFileName As Long) As Long

    Then use stringPointer to point to the file.

    DeleteFile strPtr("D:\?-Tö+")
    thanks 4 the answer guys ... but,

    there's no error message for this function, but ... the file is still exist in my D:\ Drive, is there any problem how to write the code ?

    actuallly, in windows explorer filename not "?-Tö+", but it's like just a square ...

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [help] how to delete file with unicode filepath

    How are you getting the file name? I doubt you want to hardcode it. Unless your regional settings are the foreign language, VB's Dir() should not return valid results, neither will a FileListBox. You will want to look at using more APIs to get the file name, depending on how you are getting that name to start with.

    You cannot type unicode text into the code window but you can create unicode text in various ways, such as using a byte array then applying StrConv() to that array to return a unicode string that can be passed to unicode version APIs.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Re: [help] how to delete file with unicode filepath

    Quote Originally Posted by LaVolpe View Post
    How are you getting the file name? I doubt you want to hardcode it. Unless your regional settings are the foreign language, VB's Dir() should not return valid results, neither will a FileListBox. You will want to look at using more APIs to get the file name, depending on how you are getting that name to start with.

    You cannot type unicode text into the code window but you can create unicode text in various ways, such as using a byte array then applying StrConv() to that array to return a unicode string that can be passed to unicode version APIs.
    i just use 'alt' button and press numeric keyboard,, and so, what should i do now ? to delete the unicode filename ?

  7. #7
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [help] how to delete file with unicode filepath

    Mozzart....

    What LaVolpe is asking is, HOW you are telling VB that the File is there?

    Through a list box ? or is it typed in directly in the IDE?

    Also that filename doesn't seem to have a file extension! Not that i think is an invalid thing to do, but you might want to make sure the file exists before your use the DeleteFile api.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Re: [help] how to delete file with unicode filepath

    Quote Originally Posted by some1uk03 View Post
    Mozzart....

    What LaVolpe is asking is, HOW you are telling VB that the File is there?

    Through a list box ? or is it typed in directly in the IDE?

    Also that filename doesn't seem to have a file extension! Not that i think is an invalid thing to do, but you might want to make sure the file exists before your use the DeleteFile api.
    oh, i'm sorry, my english translate is really bad ..

    i get the filename from .... common dialog controls ... for the filename that doesn't have any extension, it's ok right ?

  9. #9
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [help] how to delete file with unicode filepath

    ok.. in that case you should use the CommonDialog APi to be able pass the Unicode Filename, otherwise the default CommonDialog wouldn't return the correct path.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  10. #10

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    32

    Re: [help] how to delete file with unicode filepath

    Quote Originally Posted by some1uk03 View Post
    ok.. in that case you should use the CommonDialog APi to be able pass the Unicode Filename, otherwise the default CommonDialog wouldn't return the correct path.
    okay,, but .. how is it ? can u tell me ?

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [help] how to delete file with unicode filepath

    You can search this forum and google for more examples. The keywords to search are: unicode & getopenfilename.
    Example on this site
    Example on another site
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width