Creating directory preserving name case
MSDN:
- CreateDirectory function - Creates a new directory one level at a time
- SHCreateDirectory function - Creates a new directory including all intermediate folders, if necessary
- CreateFolder Method - WSH
- NewFolder Method - Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 * WIN API lcNewFolder = "C:\Test\TEST2\test3\TeSt4" ? MakeDir(lcNewFolder) ? SHMakeDir(lcNewFolder) *--------------------------------------------------- * CreateDirectory - one level at a time FUNCTION MakeDir(tcNewFolder) LOCAL laList[1], lcTemp, lnI, llOK = ALINES(laList, tcNewFolder, "\") lcTemp = laList[1] llOK = .T. FOR lnI=2 TO ALEN(laList) lcTemp = lcTemp + "\"+ laList[lnI] IF NOT DIRECTORY(lcTemp) llOK = CreateDirectory(lcTemp, 0) <> 0 IF NOT llOK EXIT ENDIF ENDIF ENDFOR RETURN llOK AND DIRECTORY(tcNewFolder) FUNCTION CreateDirectory(tcNewFolder, tnSecurityAttributes) DECLARE Long CreateDirectory IN WIN32API ; String lpPathName, Long lpSecurityAttributes RETURN CreateDirectory(tcNewFolder, tnSecurityAttributes) *---------------------------------------------------------------- * SHCreateDirectory - may not be avaialble in the future versions of Windows FUNCTION SHMakeDir(tcNewFolder) RETURN SHCreateDirectory(0, STRCONV(tcNewFolder,5)) = 0 FUNCTION SHCreateDirectory(tnhWnd, tcNewFolder) DECLARE Long SHCreateDirectory IN shell32.dll Long hwnd, String pszPath RETURN SHCreateDirectory(tnhWnd, tcNewFolder)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 * WSH lcNewFolder = "C:\Test\TEST2\test3\TeSt4" ? MakeDir(lcNewFolder) *--------------------------------------------------- * CreateFolder FUNCTION MakeDir(tcNewFolder) LOCAL laList[1], lcTemp, lnI, llOK, loFSO loFSO = CreateObject("Scripting.FileSystemObject") = ALINES(laList, tcNewFolder, "\") lcTemp = laList[1] llOK = .T. FOR lnI=2 TO ALEN(laList) lcTemp = lcTemp + "\"+ laList[lnI] IF NOT DIRECTORY(lcTemp) TRY loFSO.CreateFolder(lcTemp) CATCH TO oExp llOK = .F. ENDTRY IF NOT llOK EXIT ENDIF ENDIF ENDFOR RETURN llOK AND DIRECTORY(tcNewFolder)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 * Shell lcNewFolder = "C:\Test\TEST2\test3\TeSt4" ? MakeDir(lcNewFolder) *--------------------------------------------------- * NewFolder FUNCTION MakeDir(tcNewFolder) LOCAL loShellApp, lcRoot, loRoot, llOK llOK = .T. loShellApp = CREATEOBJECT("Shell.Application") lcRoot = LEFT(tcNewFolder,3) loRoot = loShellApp.NameSpace(lcRoot) TRY loRoot.NewFolder(SUBSTR(tcNewFolder,4)) CATCH TO oExp llOK = .F. ENDTRY RETURN llOK
Comments