Question : What is the best way in FoxPro to move or copy a file and preserve the original filename case?

Foxpro seems to love to convert things to lowercase, which is a real shortcoming of the language. This should be a simple flag somewhere, but isn't.

What is the best method to make sure the case is preserved when coping a file from one directory to another using the copy file command?

I would love to just do this with foxpro somehow, but if a windows api is necessary for it "so be it".

Thank for the help!

BC

Answer : What is the best way in FoxPro to move or copy a file and preserve the original filename case?

I am still flying in propeller plane and trying to find some enhancement possibility in your code... and here it is. The following code has case insensitive parameters but it preserves upper/lower case of copied/moved file names.

BTW, was it turbojet or rocket jet?
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:
FUNCTION MoveFilePreserveCase
LPARAMETERS lcOrigPathAndFileName, lcNewPath

LOCAL laArr[1], llDeclared, lnFiles, lcTrueName, llOK

llDeclared = ADLLS(laArr) > 0 AND ASCAN(laArr, 'MoveFile', 1, -1, 1, 6) > 0

IF !llDeclared
  DECLARE integer MoveFile IN kernel32.dll string ExistingFile, string NewFile 
ENDIF

lnFiles = ADIR(laArr, lcOrigPathAndFileName, "", 1)
IF lnFiles = 1
  llOK = MoveFile(ADDBS(JUSTPATH(lcOrigPathAndFileName)) + laArr[1,1] , ;
                  ADDBS(lcNewPath) + laArr[1,1]) <> 0
ENDIF

RETURN llOK

FUNCTION CopyFilePreserveCase
LPARAMETERS lcOrigPathAndFileName, lcNewPath 

LOCAL laArr[1], llDeclared, lnFiles, lcTrueName, llOK

llDeclared = ADLLS(laArr) > 0 AND ASCAN(laArr, 'CopyFile', 1, -1, 1, 6) > 0

IF !llDeclared
  DECLARE integer CopyFile IN kernel32.dll string ExistingFile, string NewFile 
ENDIF

lnFiles = ADIR(laArr, lcOrigPathAndFileName, "", 1)
IF lnFiles = 1
  llOK = CopyFile(ADDBS(JUSTPATH(lcOrigPathAndFileName)) + laArr[1,1] , ;
                  ADDBS(lcNewPath) + laArr[1,1]) <> 0
ENDIF

RETURN llOK
Random Solutions  
 
programming4us programming4us