Creating directory preserving name case
By Sergey - Posted on February 15th, 2008
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
1 day 17 hours ago
6 days 1 hour ago
6 days 2 hours ago
1 week 2 days ago
1 week 2 days ago
2 weeks 3 days ago
2 weeks 3 days ago
2 weeks 6 days ago
2 weeks 6 days ago
3 weeks 18 hours ago