Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

path/file naming problem due to embedded spaces 1

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
I also mentioned this in thread184-1695373
But as this in fact has nothing to do with that subject I decided to start a new thread.
I have a path/file naming problem.
Using Azip the actual zip action's syntax is : lnFilesInZip = Azip(.T. ,lcArchiefnaam , lcWhat2Backup)
lnFilesInZip returns the number of files which has been zipped.
lcArchiefnaam is the name of the zipfile
lcWhat2Backup contains the path with the files which must be zipped.

The latter caused my failure.
I always had a relative path <"data\*.*" > to the files and I changed it in a full-path naming.
<"c:\program files\myapp\data\*.*">
But [beginners fault] this may not contain any space in the file name.

The stupid thing: I faced this problem also years ago (problem of 55+ age)
I can't remember how I fixed that.

Any suggestion:
"data\*.*" works fine wheras
"c:\program files\myapp\data\*.*" fails

Any suggestions? I have to update as my data-files can't stay in sub-folder of my app due to win7 restrictions.

As documentation here is the original code of Stephan Darlington

Code:
*********************************************************************************************************
* Azip procedure to zip files for Visual FoxPro using the
* AddZip AZIP32.DLL from shareware
* [URL unfurl="true"]http://ourworld.compuserve.com/homepages/Stephen_Darlington/addzip.htm[/URL]
* Requirements: AZIP32.DLL in your Windows\system directory or current directory
*
* USAGE: AZIP(lInitialize, sArchive, sInclFiles[, ZipParams])
*
* Example: AZIP(.T., "ZIPFILE", "*.DBF *.TXT Customer.doc")
*
* PARAMETERS:
*-- lInitialize: .T. first time & Done only once before or when starting file zip - .F. afterward
*-              Calling azip() with no params also initializes
*-- sArchive: Archive FileName with extension - Example "C:\THISFILE.ZIP"
*-- sInclFiles: String repr. file(s) to include
*--		Example1 "D:\CUSTDATA.DBF"
*--     Example2 "C:\CUSTOMER.DBF D:\*.TXT D:\DATABASES\*.*" - only single spaces in between
*--     ZIPparams: Some compression parameters [Optional]
*                  e(x) x = 'X' maximum compression
*                       x = '0' no compression (digital 0 not O)
*                       x = 'S' minimal compression
*                       x = 'N' normal compression (default)
*                  P include directory entries
*                  Spassword must be last part
*
* Return Values: the number of files archived or -1 if archive name not specified.


********************************************************************************************
FUNCTION aZip
PARAMETERS lInitialize, sArchive, sInclFiles, ZIPparams
PRIVATE Params, sTemp

Params = PARAMETERS()

* declare needed DLL functions & pass current window
IF Params = 0 OR lInitialize
	PRIVATE HWND
	DECLARE INTEGER GetActiveWindow 					IN win32api
	HWND = GetActiveWindow()
	DECLARE addZIP_Initialise 							IN AZIP32
	DECLARE SHORT addZIP_SetParentWindowHandle 			IN AZIP32 SHORT @ HWindow
	DECLARE SHORT addZIP_ArchiveName 					IN AZIP32 STRING @ sArchName
	DECLARE SHORT addZIP_Include 						IN AZIP32 STRING @ sFileName
	DECLARE SHORT addZIP_Recurse 						IN AZIP32 SHORT @ nRecurse
	DECLARE SHORT addZIP_SetCompressionLevel 			IN AZIP32 SHORT @ nComprLvl
	DECLARE SHORT addZIP_IncludeDirectoryEntries 		IN AZIP32 SHORT @ nInclDir
	DECLARE SHORT addZIP_IncludeEmptyDirectoryEntries 	IN AZIP32 SHORT @ nInclEDir
	DECLARE SHORT addZIP_Update 						IN AZIP32 SHORT @ nUpdate
	DECLARE SHORT addZIP_Update 						IN AZIP32 SHORT @ nUpdate
	DECLARE SHORT addZIP 								IN AZIP32
	DECLARE SHORT addZIP_Register 						IN AZIP32 String @ RegName, Integer @ RegNum
	DECLARE SHORT addZIP_Encrypt 						IN AZIP32 STRING @ sPassw
	addZIP_Initialise()
	addZIP_SetParentWindowHandle(HWND)
	* addZIP_Register("RegistrationName", RegistrationNumber)
	* Do above line if you have registered the software - it permits passwords

	IF Params < 2
    	RETURN 0
	ENDIF
ENDIF

IF Params < 3
	?? CHR(7)
	MESSAGEBOX('Missing parameters!',0, 'AZip Notice!')
	RETURN 0
ENDIF

IF Params > 3 && ZIPparams exist
	ZIPparams = ALLT(ZIPparams)
	PRIVATE LastPos, PASSWORD, nCurPos
	LastPos = LEN(ZIPparams) + 1

	* check for password
	nCurPos = ATC('S', ZIPparams)
	IF nCurPos > 0
    	cPassWord = SUBSTR(ZIPparams, nCurPos+1)
    	addZIP_Encrypt(cPassWord)
    	ZIPparams = LEFT(ZIPparams, nCurPos -1) && now remove password part - it may have other code
	ENDIF

	* check for storing subdirectory information
	nCurPos = ATC('P', ZIPparams)
	IF nCurPos > 0
    	addZIP_Recurse(1)
    	addZIP_IncludeDirectoryEntries(1)
    	* addZIP_IncludeEmptyDirectoryEntries(1)
	ENDIF

	* check for compresion level
	nCurPos = ATC('E', ZIPparams)
	IF nCurPos > 0
    	PRIVATE cCompLevel, nCompLevel
    	cCompLevel = SUBSTR(ZIPparams, nCurPos + 1, 1)
    	DO CASE
    	CASE cCompLevel = 'X' && max compression
      		nCompLevel = 3
    	CASE cCompLevel = 'S' && min compression
      		nCompLevel = 1
    	CASE cCompLevel = '0' && no compression
      		nCompLevel = 0
    	OTHERWISE && normal/default compression
      		nCompLevel = 2
    	ENDCASE
    	addZIP_SetCompressionLevel(nCompLevel)
	ENDIF
ELSE
	addZIP_SetCompressionLevel(2)
ENDIF

addZIP_ArchiveName(sArchive) && specify archive filepath
sInclFiles = ALLT(STRTRAN(sInclFiles, ' ', '|')) && file(s) to zip
addZIP_Include(sInclFiles) && (sInclFiles)


Return addZIP() && do it & return # of files compressed

***************************************************************************************
Function aUnzip
* Azip procedure to unzip files for Visual FoxPro using the
* AddZip AUNZIP.DLL's from shareware
* [URL unfurl="true"]http://ourworld.compuserve.com/homepages/Stephen_Darlington/addzip.htm[/URL]
*
* Requirements: AUNZIP32.DLL in your Windows\system directory or current directory
*
* USAGE: AUNZIP(lInitialize, sArchive sDir[, sExtractFiles[, UnZIPparams]])
*
* PARAMETERS:
*-- lInitialize: .T. first time & Done only once beforeor when starting file zip - .F. afterward
*-              Calling azip() with no params also initializes
*-- sArchive: Archive FileName with extension - Example "C:\THISFILE.ZIP"
*-- sDir: destination directory string
*--		Example1 "D:\TEMP"
*-- sExtractFiles(optional): string repr. file(s) or types to extract
*--     Default is "*.*"
*--     Example1 "C:\CUSTOMER.DBF"
*--     Example2 "C:\CUSTOMER.DBF D:\*.TXT D:\DATABASES\*.*" - only single spaces in between
*-- UnZIPparams: Some compression parameters [Optional]
*                F freshen files - over older date/time or not existing
*                D include directory information
*                Overwrite: !!!!
*                   !!!! This does not seem to work except OverwriteNone - as of Aug. 1998 version.
*                        OA: overwrite all (default)
*                        O0: do not overwrite (letter O, digit 0)
*                        OU: ask user
*                Spassword (Must be last part - works only with registered version)
*
* Return Values: the number of files archived or -1 if archive name not specified.

PARAMETERS Initialize, sArchive, sDir, sExtractFiles, UnZIPparams
PRIVATE Params, sTemp
Params = PARAMETERS()
* declare needed DLL functions & pass current window
IF Params = 0 OR Initialize
  PRIVATE HWND
  DECLARE INTEGER GetActiveWindow 				IN win32api
  HWND = GetActiveWindow()
  DECLARE addUNZIP_Initialise 					IN AUNZIP32
  DECLARE SHORT addUNZIP_SetParentWindowHandle 	IN AUNZIP32 SHORT @ HWindow
  DECLARE SHORT addUNZIP_ArchiveName 			IN AUNZIP32 STRING @ sArchName
  DECLARE SHORT addUNZIP_RestoreStructure 		IN AUNZIP32 SHORT @ nResStr
  DECLARE SHORT addUNZIP_Freshen 				IN AUNZIP32 SHORT @ nFreshn
  DECLARE SHORT addUNZIP_Include 				IN AUNZIP32 STRING @ sFileName && default is *.*
  DECLARE SHORT addUNZIP_ExtractTo 				IN AUNZIP32 STRING @ sExtrTo
  DECLARE SHORT addUNZIP_Register 				IN AUNZIP32 STRING @ RegName, INTEGER @ RegNum
  DECLARE SHORT addUNZIP_Decrypt 				IN AUNZIP32 STRING @ sPassw
  DECLARE SHORT addUNZIP_Overwrite 				IN AUNZIP32 SHORT @ nOvLevel
  DECLARE SHORT addUNZIP 						IN AUNZIP32
  addUNZIP_Initialise()
  addUNZIP_SetParentWindowHandle(HWND)
* addUNZIP_Register("RegistrationName", RegistrationNumber)
  IF Params < 2
    RETURN 0
  ENDIF
ENDIF

IF Params < 3
  ?? CHR(7)
  MESSAGEBOX('Missing parameters!',0, 'AUNZip Notice!')
  RETURN 0
ENDIF

IF Params > 3 && UnZIPparams exist
  UnZIPparams = ALLT(UnZIPparams)
  PRIVATE LastPos, PASSWORD, nCurPos
  LastPos = LEN(UnZIPparams) + 1

  * check for password
  nCurPos = ATC('S', UnZIPparams)
  IF nCurPos > 0
    cPassWord = SUBSTR(UnZIPparams, nCurPos+1)
    addUNZIP_Decrypt(cPassWord)
    UnZIPparams = LEFT(UnZIPparams, nCurPos -1) && now remove password part - it may have other code
  ENDIF

  * check for restoring subdirectory information
  nCurPos = ATC('D', UnZIPparams)
  IF nCurPos > 0
    addUNZIP_RestoreStructure(1)
  ENDIF

  * check for freshen
  nCurPos = ATC('F', UnZIPparams)
  IF nCurPos > 0
    addUNZIP_RestoreStructure(1)
  ENDIF

  * check for Overwrite - this does not seem to work except, OverwriteNone
  DO CASE
  CASE 'OA' $ UnZIPparams && Overwrite all
    addUNZIP_Overwrite(0x0b)
  CASE 'O0' $ UnZIPparams && overwrite none
    addUNZIP_Overwrite(0x0c)
  CASE 'OU' $ UnZIPparams && overwrite ask user
    addUNZIP_Overwrite(0x0a)
  ENDCASE

  IF nCurPos > 0
    addUNZIP_RestoreStructure(1)
  ENDIF

ELSE
  addUNZIP_Overwrite(0x000a) && this does not seem to work except OverwriteNone
ENDIF

addUNZIP_ArchiveName(sArchive)
addUNZIP_ExtractTo(ALLT(sDir))
sExtractFiles = IIF(Params<4, "*.*", ALLT(STRTRAN(sExtractFiles, ' ', '|'))) 	&& file(s) to extract
addUNZIP_Include(sExtractFiles) 												&& files to extract - *.txt, *.*, etc.
RETURN addUNZIP()
TIA
-Bart

Fo
 
The parameter you ask for is described in the AZIP header as:
*-- sInclFiles: String repr. file(s) to include
*-- Example1 "D:\CUSTDATA.DBF"
*-- Example2 "C:\CUSTOMER.DBF D:\*.TXT D:\DATABASES\*.*" - only single spaces in between

This alone says spaces seperate single files or fileskeletons (with * or ? as jokers), so the simple solution is to put files you want to zip into directories with no space in theyr names.

The typical solution in case of DOS commands is to put such names into quotes themselves, which you may simply try.

eg "'c:\program files\myapp\data\*.*'" (notice the single quotes within the string.

It get's clearer, if there is a list of files/fileskeletons involved as in
"*.dbf *.fpt *.dbf 'c:\program files\myapp\data\*.*' yourapp.*"

You may need to specify double quote inside instead of single quotes. Then just swap your usage of inner and outer qoutes and pass on '*.dbf *.fpt *.dbf "c:\program files\myapp\data\*.*" yourapp.*' or in your case '"c:\program files\myapp\data\*.*"'

Bye, Olaf.
 
Quotation won't help, because of another thing I notice, looking into how AZIP processes the sInclFiles parameter, which you could also see on your own:

Code:
sInclFiles = ALLT(STRTRAN(sInclFiles, ' ', '|')) && file(s) to zip
addZIP_Include(sInclFiles) && (sInclFiles)

So any space in this parameter is replaced with a | char, therefor simply inactivate that STRTRAN, and in case you would specify more than one file or file skeleton, seperate them by | instead of space and all is fine.

Code:
sInclFiles = ALLT(STRTRAN(sInclFiles, ' ', '|')) && file(s) to zip
addZIP_Include(sInclFiles)

That's all.

Bye, Olaf.
 
Hm, the change didn't come over:

Code:
*sInclFiles = ALLT(STRTRAN(sInclFiles, ' ', '|')) && file(s) to zip
addZIP_Include(sInclFiles)

The header section would then need to change it's examples about that parameter:
Code:
*-- sInclFiles: String repr. file(s) to include
*--	Example1 "D:\CUSTDATA.DBF"
*--     Example2 "C:\CUSTOMER.DBF|D:\*.TXT|D:\MY DATABASES\*.*" - only | in between files
That way it shows you can use spaces in file names.

The AZIP.DLL itself, specifically it's function addZIP_Include(sFiles) expects files seperated by |, not by space, which is clever, as its a) a good visual separation and b) a char which unlike space is not allowed in file names.

Bye, Olaf.
 
Olaf, Thanks for digging into this code. But I'm afraid this still don't solve my prob. re fullpath/filename whenever there's an embedde space. Is n't it?
-Bart
 
In addition, I am going to check if I can use set default based upon path/filename prior to do the aZip and afterwards set default back to it's original setting.
Will report back here!
-Bart
 

Try by putting the path within brackets ("c:\program files\myapp\data\*.*")

 
Bart, it does solve your problem, if you don't replace spaces with |. Because that renders your path invalid.

Bye, Olaf.
 
In detail:

? ALLT(STRTRAN("c:\program files\myapp\data\*.*", ' ', '|')) && file(s) to zip

This returns "c:\program|files\myapp\data\*.*". And that can't work, can it?
The folder isn't called program|files, is it?

So first test, and then come back with your findings. AZIP might also use space additional as a separator additional to |, yes. But I can't test that for you, I don't have AZIP.DLL.

You also were alredy pointed to several alternatives, which are very easy to use. Especially the VFPCompression.fll is an FLL, foxpor link library, which introduces a new "native" Foxpro zip command. Don't you know FLLs? Foxtools.FLL at least?

Bye, Olaf.
 
Hi Olaf,
Yes, I do know Graig's zip FLL.
But as I used the aZip32.dll together with aUnzip32.dll allready for many years I should like to continue with that but just taylor it due to the win7 requirments i.e. no data-dir just beneath exe-dir. One of the secundairy nice things of aZip.DLL is that it returns the number of files inside the ZIP.
I use that as check to see if things work as expected.
-Bart
 
VFPcompression offers that, too.

Besides, as you try to compress "c:\program files\myapp\data\*.*" it doesn't look anything like tayloring it to Win7, you ARE still trying to zip within the program files app sub dir. If you just move the data to any directory not containing any spaces in it's path the problem would also be solved.

Why don't you start by removing the STRTRAN and see, if it works? Then all other discussion is mute, but valid, if it doesn't work. There is not much trying and poking around with AZIP to do besides that. It's easier to introduce VFPCompression, instead of trying to ride that dead horse, then.

Bye, Olaf.
 
Olaf,
In proces of changing datapath I first need to be sure that my backup facility continue to do what is expected.
In this case: make independent of yes/no embedded spaces.So enabling users to have a map wherever they like, even in a map with embedded spaces in it's name.
As part of that I sure will test your advice and report back.

I had a look at VFPcompression but probably I overlooked the possibility to see how many files are inside the ZIP.
I will have a closer look.
-Bart
 
Hi Olaf!

I don't do it that often but I grand you a star for this solution.
In other words: you solved my problem.

I removed:
sInclFiles = ALLT(STRTRAN(sInclFiles, ' ', '|')) && file(s) to zip

And that was it.....

Thanks again for sharing your knowledge.

-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top