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
| This is sample code. Add error handling and adjust to your requirements as necessary. |
* 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)
* 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)
* 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
Recent comments
12 hours 32 min ago
1 day 19 hours ago
1 day 19 hours ago
2 days 15 hours ago
2 days 22 hours ago
4 days 6 hours ago
4 days 22 hours ago
5 days 11 hours ago
1 week 1 day ago
2 weeks 5 days ago