Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create folder and copy data into it
Message
De
28/09/2004 10:56:47
 
 
À
28/09/2004 02:50:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00946159
Message ID:
00946685
Vues:
24
The below will copy all subfolders and files in cfolder1 to cfolder2. Only files that meet the criteria in cfilter will be copied IF cfilter equals anything except "" (an empty string):
LOCAL cFolder, nResult
cFolder1 = "C:\profiler32\data"
cFolder2 = "c:\temp1"
cfilter = ""
*cfilter = ".dbf"
cfiles = cFolder1+"\*.*"

DECLARE INTEGER CreateDirectory IN kernel32;
	STRING lpPathName, INTEGER lpSecurityAttr

IF !DIRECTORY(cFolder2)
	IF CreateDirectory (cFolder2, 0) = 0
		=MESSAGEBOX('Could not create '+cFolder2)
		RETURN
	ENDIF
	IF !DIRECTORY(cFolder2)
		=MESSAGEBOX('Could not create '+cFolder2)
		RETURN
	ENDIF
ENDIF

llresult = .T.

IF ADIR(allfiles,cfiles,"D") > 0

	DIMENSION dirs(1,2)
	=GetSubDirs(cFolder1)
	IF TYPE('dirs(ALEN(dirs,1),1)') = "C" .AND. !EMPTY(dirs(ALEN(dirs,1),1))
		DIMENSION dirs(alen(dirs,1)+1,2)
	ENDIF
	dirs(alen(dirs,1),1)=cFolder1
	dirs(alen(dirs,1),2)=cFolder2
	FOR it = 1 TO ALEN(dirs,1)
		=GetSubDirs(dirs(it,1))
	ENDFOR

	DECLARE INTEGER CopyFile IN kernel32;
		STRING  lpExistingFileName,;
		STRING  lpNewFileName,;
		INTEGER bFailIfExists

	FOR ik = 1 TO ALEN(dirs,1)	&& process all subdirectories
		cfoldera = dirs(ik,1)
		cfolderc = dirs(ik,2)
		*--Create the directory
		IF !DIRECTORY(dirs(ik,2))
			llresult = makedir(dirs(ik,2))
			IF !llresult
				EXIT
			ENDIF
		ENDIF
		*--Get its files
		IF ADIR(callfiles,dirs(ik,1)+"\*.*") > 0
			FOR i = 1 TO ALEN(callfiles,1)
				IF !"D" $ callfiles(i,5)
					IF !EMPTY(cfilter)
						IF UPPER(cfilter) $ UPPER(callfiles(i,1))
							=CopyFile(cfoldera+"\"+callfiles(i,1), cfolderc+"\"+callfiles(i,1), 0)
						ENDIF
					ELSE
						=CopyFile(cfoldera+"\"+callfiles(i,1), cfolderc+"\"+callfiles(i,1), 0)
					ENDIF
				ENDIF
			ENDFOR
		ENDIF
	ENDFOR
	IF !llresult
		=MESSAGEBOX('An Error Ocurred')
	ENDIF
ELSE
	=MESSAGEBOX('No matching files found to copy.')
ENDIF
RETURN llresult



*-----------------------------------------------------------------------
PROCEDURE cd1(cFolder)
DECLARE INTEGER SHCreateDirectory IN shell32;
	INTEGER HWND, STRING pszPath

nResult = SHCreateDirectory(0, a2u(m.cFolder))
IF nResult <> 0
	? "Error code:", nResult
ENDIF

PROCEDURE cd2(cFolder)
DECLARE INTEGER CreateDirectory IN kernel32;
	STRING lpPathName, INTEGER lpSecurityAttr

IF CreateDirectory (cFolder, 0) = 0
	DECLARE INTEGER GetLastError IN kernel32
	*   3 = ERROR_PATH_NOT_FOUND
	*   5 = ERROR_ACCESS_DENIED
	* 183 = ERROR_ALREADY_EXISTS
	? "Error code:", GetLastError()
ENDIF

FUNCTION a2u(cText)
* simplified conversion to Unicode string
LOCAL cReturn, nIndex
cReturn = ""
FOR nIndex=1 TO LEN(cText)
	cReturn = cReturn + SUBSTR(cText, nIndex,1) + CHR(0)
ENDFOR
RETURN cReturn


PROCEDURE makedir
LPARAMETERS newfolder
IF !DIRECTORY(newfolder)
	IF CreateDirectory (newfolder, 0) = 0
		=MESSAGEBOX('Could not create '+newfolder)
		RETURN .F.
	ENDIF
	IF !DIRECTORY(newfolder)
		=MESSAGEBOX('Could not create '+newfolder)
		RETURN .F.
	ELSE
		RETURN .T.
	ENDIF
ELSE
	RETURN .T.
ENDIF

FUNCTION GetSubDirs
LPARAMETERS PrimeDir
PrimeDir = PrimeDir+IIF(RIGHT(PrimeDir,1)="\","","\")
PRIVATE MoreDirs, ip
DIMENSION MoreDirs(1,1)
nCount = ADIR(MoreDirs,PrimeDir+"*.*","DHS")
=ASORT(MoreDirs)
FOR ip = 1 TO m.nCount
	IF MoreDirs(m.ip,1) # "." AND "D" $ MoreDirs(m.ip,5)
		IF TYPE('dirs(ALEN(dirs,1),1)') = "C" .AND. !EMPTY(dirs(ALEN(dirs,1),1))
			DIMENSION dirs(alen(dirs,1)+1,2)
		ENDIF
		dirs(alen(dirs,1),1) = PrimeDir + MoreDirs(m.ip,1)
		a1 = dirs(ALEN(dirs,1),1)
		a2 = cFolder1
		a3 = cFolder2
		dirs(ALEN(dirs,1),2) = STRTRAN(a1,a2,a3)
		=GetSubDirs(dirs(alen(dirs,1)))
	ENDIF
ENDFOR
RETURN
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform