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

busycoder
busycoder used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CaptainCyrilFounder, Software Engineer, Data Scientist

Commented:

FUNCTION FileMove
LPARAMETERS cSourceFileName, cDestinationFileName
LOCAL lOK, cCommand
lOK = .T.
DECLARE INTEGER MoveFile IN WIN32API;
	STRING source, STRING destination
lOK = MoveFile(cSourceFileName,cDestinationFileName) <> 0
CLEAR DLLS
RETURN lOK

FUNCTION FileCopy
LPARAMETERS cSourceFileName, cDestinationFileName
LOCAL lOK, cCommand
lOK = .T.
DECLARE INTEGER CopyFile IN WIN32API;
	STRING source, STRING destination
lOK = CopyFile(cSourceFileName,cDestinationFileName) <> 0
CLEAR DLLS
RETURN lOK

Open in new window

You have to use Win32 API:
DECLARE integer MoveFile IN kernel32.dll string ExistingFile, string NewFile

LOCAL lcOrigPathAndFileName, lcNewPath
lcOrigPathAndFileName = "C:\SomePath\SomeFile.EXT"
lcNewPath = D:\NewPath

MoveFile(lcOrigPathAndFileName, ADDBS(D:\NewPath) + JUSTFNAME(lcOrigPathAndFileName))

Open in new window

It seems Captain is faster...
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

CaptainCyrilFounder, Software Engineer, Data Scientist

Commented:
I was flying a jet today rather than a propeller plane :-)
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?

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

Open in new window

CaptainCyrilFounder, Software Engineer, Data Scientist

Commented:
Olaf DoschkeSoftware Developer

Commented:
you can also use Scripting.Filesystemobject to copy files with preservance of the name.

Bye, Olaf.

Author

Commented:
Thank you all for your help!

Olaf, what is this from?

"Scripting.Filesystemobject"

Thanks!

BC
Olaf DoschkeSoftware Developer

Commented:
For example, if you have a file c:\Temp1\Original.txt and want to copy it into c:\Temp2 without becoming ORIGINAL.TXT tere. The same goes with MoveFile.


o = Createobject("Scripting.FileSystemObject")
o.CopyFile('c:\Temp1\Original.txt','c:\Temp2\')

Open in new window

Olaf DoschkeSoftware Developer

Commented:
Well, MoveFile of course moves the file then.
Olaf DoschkeSoftware Developer

Commented:
And this is "From" Windows, more precise Windows Scripting Host. You don't need to install anything to have it, despite Windows, and it's there y default since Windows 98 SE.

Bye, Olaf.

Author

Commented:
Cool, thanks I haven't used that yet, will look into for sure!!!!!
If you need some description of FSO then you may start here: http://msdn.microsoft.com/en-us/library/6tkce7xa(VS.85).aspx

FSO seems to be easier to use than DLLs, it just needs some more icebreakers...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial