4DToday.com
Home Directory Classifieds Reference Archives
Site Info
About 4DToday.com
Contact Us
Version française
Quote
Developers (723)
4D Developers (591)
Web Developers (334)
Tools Publishers (201)
Instructors (166)
Web Hosts (58)
Resellers (90)
Software Publishers (300)
Search Developers
Products (383)
Plug-Ins (104)
Components (48)
Code Libraries (9)
Books (7)
Tools (42)
Vertical Applications (148)
Search Products
User Groups
All User Groups (23)
Classified Ads (12)
Help Wanted (4)
Opportunities Wanted (8)
Hardware Wanted (0)
Hardware for Sale (0)
Software Wanted (0)
Software for Sale (0)
Other (0)
Resources
4D
4D, Inc.
4D International
4D Wiki
4D Partner Central
4D Beginner's Center
4D Online Documentation
4D 2004 Example Applications
4D Example Databases
4D BugDisplayer
4D, Inc. Training
Message Lists
4D Mailing Lists
4D Tech Google Group
iNUG Archives (Nabble)
iNUG Archives (Gmane)
iNUG Message Index
Other
4D Code Exchange
4D Resources
Sviluppo4D.it (Italy)
4D Sources (4D Plugin API, 4D Pop & Miyako
Quote
I am not young enough to know everything.
Oscar Wilde  
  Suggest a Quote  
Developer News
There are no news items at this time.
 Submit Future News    Archive 
Technical Tip
Seamless unzipping of files
Submitted by Ivan Houle, Noreast Electronics Co. Ltd.

As a follow-up from the previous Zipping tip, here is a method for uncompressing a zip file more easily than using the PHP equivalent in 4D.


  // ----------------------------------------------------
  // User name (OS): Ivan
  // Date and time: 01/07/15, 16:11:08
  // ----------------------------------------------------
  // Method: document_unzip
  // Description
  //    To uncompress a zip file into documents and folders
  //    This method currently works only on Windows (any version after XP) and uses a
  //    Visual Basic script to do the actual uncompression from Windows' shell
  //
  // Parameters
  // ----------------------------------------------------
C_TEXT($1)  //Zip document (folder) FULL path name to uncompress
C_TEXT($2)  //Folder where to put the uncompressed files and folders

C_TEXT($t_scriptPath;$t_crlf;$t_targetFolder;$t_zipName)
C_BOOLEAN($b_runScript)
C_BLOB($x_script)
C_TIME($h_docRef)

$b_runScript:=True
$t_scriptPath:=Get 4D folder(Current Resources folder)+"unzip.vbs"  //the script must be in Visual Basic
$t_zipName:=$1
$t_targetFolder:=$2

If (Test path name($t_scriptPath)#Is a document)  //If the script does not exist yet, then create it
$b_runScript:=False
$t_crlf:=Char(13)+Char(10)  //Add Char(10) to allow for easy reading in a Windows text editor like Notepad
  //Remove the following "If" if you want the script saved on any version of 4D
  //Here, it is restricted only to the server and a standalone uncompiled version
If ((Application type=4D Server) | (Application type=4D Local Mode))  //Create the script and save it in the resources folder
  //We use a blob to create the script
TEXT TO BLOB("Set objArgs = WScript.Arguments"+$t_crlf;$x_script;Mac text without length;*)
TEXT TO BLOB("' Open ZIP and copy its content into an uncompressed folder"+$t_crlf;$x_script;Mac text without length;*)
TEXT TO BLOB("Set fso = CreateObject(\"Scripting.FileSystemObject\")"+$t_crlf;$x_script;Mac text without length;*)
TEXT TO BLOB("Set sha = CreateObject(\"Shell.Application\")"+$t_crlf;$x_script;Mac text without length;*)
TEXT TO BLOB("Set ZipFile = sha.NameSpace(fso.GetAbsolutePathName(objArgs(0))).Items()"+$t_crlf;$x_script;Mac text without length;*)
TEXT TO BLOB("Set targetFolder = sha.NameSpace(fso.GetAbsolutePathName(objArgs(1)))"+$t_crlf;$x_script;Mac text without length;*)
TEXT TO BLOB("targetFolder.CopyHere ZipFile, 4"+$t_crlf;$x_script;Mac text without length;*)

BLOB TO DOCUMENT($t_scriptPath;$x_script)
$b_runScript:=(OK=1)
SET BLOB SIZE($x_script;0)

End if

End if

If ($b_runScript)
SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")  //Let's hide that ugly black DOS window
  //We are running CSCRIPT which is native to any Windows since XP
LAUNCH EXTERNAL PROCESS("cmd.exe /C start \"cscript\" \""+$t_scriptPath+"\" "+$t_zipName+" "+$t_targetFolder)

DELAY PROCESS(30)  //Allow time for script to run (for small files, this is more than enough)
  //Make sure the zip file is completely uncompressed before returning
  //To know if this process is done, we will try to open the zip
  //file for modification (read/write).  If we can, then the process is done

$t_zipName:=Replace string($t_zipName;"\"";"")  //We need to remove any quotes in case they were put in earlier
ON ERR CALL("EVENT_TRAP_ESCAPE")  //Use any empty method here or your own to prevent 4D from interrupting the process

Repeat
DELAY PROCESS(30)
$h_docRef:=Open document($t_zipName;"ZIP";Write Mode)

Until (OK=1)

ON ERR CALL("")
If ($h_docRef#?00:00:00?)
CLOSE DOCUMENT($h_docRef)
End if

End if
  Submit a Tip    Archive 
Spotlight
ANZAC Day 100 Years Remembrance
ANZAC Day 100 Years Remembrance Anzac Day is a national day of remembrance in Australia and New Zealand, and is commemorated by both countries on 25 April every year to honour members of the Australian and New Zealand Army Corps (ANZAC) who fought at Gallipoli in Turkey during World War I. It now more broadly commemorates all those who died and served in military operations for their countries. Anzac Day is also observed in the Cook Islands, Niue, and Tonga.
  Suggest a Spotlight  
Survey Results
Today, we asked you...
When did you start using 4D?
Survey Results

Your vote: (no vote)
Total votes received: 56
  Suggest a Survey  
Events
There are no events scheduled for the upcoming fortnight.
  Submit an Event