+ Reply to Thread
Results 1 to 7 of 7

Windows Compatible Folder Name

  1. #1
    Registered User
    Join Date
    08-28-2008
    Location
    bournemouth
    MS-Off Ver
    Office 2007
    Posts
    42

    Windows Compatible Folder Name

    Hi

    Have included a snippet of my code that creates Job Folders from input into an excel document.

    Please Login or Register  to view this content.
    My problem is that this creates any filename related to what is in the cell (i.e The Street,,,).
    Therefore it can create folders that aren't compatible with the windows file system.
    (The secretaries are dumping all sorts of punctuation in !!)

    Is there a function I can use before the folder is created to check that the folder name is going to be windows compatible.

    Hope someone can help

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Windows Compatible Folder Name

    Hi

    You could either remove incompatibel characters first, or you could switch error reporting off and then check whether an error occurred during running of the MkDir and if so, warn the user that the folder name was invalid (I probably prefer this approach):

    Please Login or Register  to view this content.
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    08-28-2008
    Location
    bournemouth
    MS-Off Ver
    Office 2007
    Posts
    42

    Re: Windows Compatible Folder Name

    I don't think error reporting is the way to go as no error happens.

    Vba creates the folder regardless of the name and basically becomes a folder that windows will not recognise and i have to use 'Unlocker' to get rid of.

    Thanks in advance.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Windows Compatible Folder Name

    I would have thought that if the folder name was incompatible with the file system then it couldn't be created in the first place!

    You could use a function to strip any non-alphanumeric characters out fo the folder name before you create it. Such a function could be:

    Please Login or Register  to view this content.
    The above will get rid of any characters except for underscores and alphanumerics (it will remove spaces too).

    Use in your sub like:

    Please Login or Register  to view this content.
    Richard

  5. #5
    Registered User
    Join Date
    08-28-2008
    Location
    bournemouth
    MS-Off Ver
    Office 2007
    Posts
    42

    Re: Windows Compatible Folder Name

    Unfortunately I need punctuation within the folder name.

    The folder name is made up of "concatenate" of certain cells within a row.

    The format that works is
    2009.045 - The House, The Street

    But, sometimes double spaces are entered and also double commas - These conditions make the format not work - But the folder is still created

    I was hoping some kind of API function might be available to check this prior to creation.

    Hope this explains things better.

  6. #6
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Windows Compatible Folder Name

    Double spaces and double comma don't prevent me from applying to the name of or subsequently using the new folder. Good luck with your search.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Windows Compatible Folder Name

    Using Richard's idea, all you need is a loop that will replace any illegal characters with NULL or some other character you choose:

    Please Login or Register  to view this content.
    Where:
    fnamestr - is the folder/file name built up from the various cells, and
    illegalcharset - is an array of illegal characters such as "<>,?|\*;:
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1