Jump to content

Half way there...issue with folder names..


jben
 Share

Recommended Posts

The ARRAY and RENAME ZIP FUNCTION works.

The ARRAY provides the locations to rename the zip files to DATA.zip which is performed via the RENAME ZIP FUNCTION.

The EXTRACT ZIP extracts the data from the DATA.zip file to the directory it is currently located within. However I'm trying to figure out how I can output the data to C:\OUTPUT...But the only problem with this is everytime the array gets the next folder it just overwrites the C:\OUTPUT data as the folder is always MASTER...

Anyone have any ideas on a way forward?...Thanks

Global $targetDir
Global $aZipList

;*************ARRAY****************
Dim $F_Folders[20],$F_Array[20];array to provide data for the Func _Rename
$F_Folders[1] = "C:\EXTRCT_TEMP\23790N_SERAIL_10409\"
$F_Folders[2] = "C:\EXTRCT_TEMP\26704P_SERIAL_10366\"
$F_Folders[3] = "C:\EXTRCT_TEMP\22059A_SERIAL_10229\"
$F_Folders[4] = "C:\EXTRCT_TEMP\23603K_SERIAL_10367\"
$F_Folders[0] = 4
For $n = 1 to $F_Folders[0]
  $F_Array [$n] = _Rename($F_Folders[$n])
next 

;*********RENAME ZIP FUNCTION*******************************************************************

Func _Rename( $F_list);this function renames zip files located in the folder specified
;in the array
    Local $I, $target, $aZipList
    Local $Flist = __FldrListToArray($F_list,0)
    For $I = 1 To Ubound($Flist) -1
     $targetDir = $Flist[$I]
     MsgBox(0, "", $targetDir)
     $aZipList = _FileListToArray($targetDir,"*.zip",0)
     If IsArray($aZipList) Then FileMove($targetDir & $aZipList[1], $targetDir & "DATA_CHILD.zip")
         
        _Extract( $F_list);calls the extract function to extract the data from the zip files
    Next
Return $aZipList
EndFunc


;*********EXTRACT ZIP FUNCTION********************************************************************
Func _Extract( $F_list)

$szZipFile = $targetDir &"DATA_CHILD.zip";this is the zip file to extract
$szDestDir = ("c:\OUTPUT")this is the destination to extract the zip files

$aZipList = _ZipList2Array($szZipFile)
for $x =0 to UBound($aZipList)-1
    $file_type = StringLower(StringRight($aZipList[$x][1],4))
    If $file_type = ".ncp" Or $file_type = ".lcn" Then
      ConsoleWrite("Extracting:"&$aZipList[$x][1])
         $vResult = _ZipUnZipItem($szZipFile,$aZipList[$x][1],$szDestDir)
        ConsoleWrite(" -- "&_ZipFormatMessage($ZR_RECENT)&@lf)
endif
Next
endfunc
Edited by jben
Link to comment
Share on other sites

This is the idea I have come up with, not sure if this is such a good idea?.

Global $targetDir
Global $aZipList



;*********RENAME ZIP FUNCTION*******************************************************************

;*************ARRAY RENAME****************
Dim $F_Folders[20],$F_Array[20];array to provide data for the Func _Rename
$F_Folders[1] = "C:\EXTRCT_TEMP\23790N_SERAIL_10409\"
$F_Folders[2] = "C:\EXTRCT_TEMP\26704P_SERIAL_10366\"
$F_Folders[3] = "C:\EXTRCT_TEMP\22059A_SERIAL_10229\"
$F_Folders[4] = "C:\EXTRCT_TEMP\23603K_SERIAL_10367\"
$F_Folders[0] = 4
For $n = 1 to $F_Folders[0]
  $F_Array [$n] = _Rename($F_Folders[$n])
next 

Func _Rename( $F_list);this function renames zip files located in the folder specified
;in the array
    Local $I, $target, $aZipList
    Local $Flist = __FldrListToArray($F_list,0)
    For $I = 1 To Ubound($Flist) -1
     $targetDir = $Flist[$I]
     MsgBox(0, "", $targetDir)
     $aZipList = _FileListToArray($targetDir,"*.zip",0)
     If IsArray($aZipList) Then FileMove($targetDir & $aZipList[1], $targetDir & "DATA_CHILD.zip")
         
        _Extract( $F_list);calls the extract function to extract the data from the zip files
    Next
Return $aZipList
EndFunc


;*********EXTRACT ZIP FUNCTION********************************************************************


;*************ARRAY EXTRACT****************
Dim $F_Extract[20],$F_Array[20];array to provide data for the Func _Rename
$F_Extract[1] = "C:\OUTPUT\FOLDER1"
$F_Extract[2] = "C:\OUTPUT\FOLDER2"
$F_Extract[3] = "C:\OUTPUT\FOLDER3"
$F_Extract[4] = "C:\OUTPUT\FOLDER4"
$F_Extract[0] = 4
For $n = 1 to $F_Extract[0]
  $F_Array [$n] = _Extract($F_Extract[$n])
next 


Func _Extract( $F_list)

$szZipFile = $targetDir &"DATA_CHILD.zip";this is the zip file to extract
$szDestDir = $Flist;this is the destination to extract the zip files

$aZipList = _ZipList2Array($szZipFile)
for $x =0 to UBound($aZipList)-1
    $file_type = StringLower(StringRight($aZipList[$x][1],4))
    If $file_type = ".ncp" Or $file_type = ".lcn" Then
      ConsoleWrite("Extracting:"&$aZipList[$x][1])
         $vResult = _ZipUnZipItem($szZipFile,$aZipList[$x][1],$szDestDir)
        ConsoleWrite(" -- "&_ZipFormatMessage($ZR_RECENT)&@lf)
endif
Next
Edited by jben
Link to comment
Share on other sites

just tried the code and it sort of works...But for some reason it extracts the contents of the zip file within C:\EXTRCT_TEMP\23603K_SERIAL_10367\ into all 4 folders..Anyone got any ideaS?

thanks

Link to comment
Share on other sites

Hey I'm trying to set up a test environment so I can run your code, but can you either pm me or post the whole code? (or is it huge?) I took your code above but I can't run that as I'm missing the value for some variables.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

I will put it all in a zip and attach it here..Thanks alot mate i'm really grateful..This is really killing my brain...

Give me 5 minutes

UPDATE

----------

PM sent

Edited by jben
Link to comment
Share on other sites

Hey someone... I have posted the code here because I tried PMing you and it doesn't seem to be working

_ZipPlugin.au3 and folder.au3 goes in the Autoit INCLUDE folder in a folder called MyExtras (you can see this referenced in the code)

The .dll is just @script so I just left it in the dir of the code...

Other than that...All you need is an c:\INPUT and c:\OUTPUT folder...Put the updates.zip in the INPUT folder and run the code...

thanks

Extractor.zip

Edited by jben
Link to comment
Share on other sites

Hey someone... I have posted the code here because I tried PMing you and it doesn't seem to be working

_ZipPlugin.au3 and folder.au3 goes in the Autoit INCLUDE folder in a folder called MyExtras (you can see this referenced in the code)

The .dll is just @script so I just left it in the dir of the code...

Other than that...All you need is an c:\INPUT and c:\OUTPUT folder...Put the updates.zip in the INPUT folder and run the code...

thanks

Judging by a quick look at your first post I think your _rename function needs to be more like this

Func _Rename($F_list);this function renames zip files located in the folder specified
;in the array
    Local $I, $J, $target, $aZipList, $ZipFile
    Local $Flist = __FldrListToArray($F_list, 0)
    For $I = 1 To UBound($Flist) - 1
        $targetDir = $Flist[$I]
        MsgBox(0, "", $targetDir)
        $aZipList = _FileListToArray($targetDir, "*.zip", 1);<-- last param changed to 1 so we only get files (unlikely to make any difference
        If IsArray($aZipList) Then
            For $J = 1 To UBound($aZipList) - 1
                $ZipFile = $targetDir & "DATA_CHILD" & $J & ".zip"
                FileMove($targetDir & $aZipList[$J], $ZipFile)
                _Extract($ZipFile);calls the extract function to extract the data from the zip files
            Next
        EndIf

    Next
    Return $aZipList
EndFunc  ;==>_Rename

There might be more than one zip file so I wasn't sure if you wanted to keep copies of them all or just overwrite each one with a file of the same name. If you don't want the copies then adding the count to the file name like I did is not needed and you can go back to calling all the copies DATA_CHILD.ZIP. However, if you don't need copies I don't see why you copy it at all, why not just pass the file name to _Extract? Like this

Func _Rename($F_list);this function renames zip files located in the folder specified
;in the array
    Local $I, $J, $target, $aZipList
    Local $Flist = __FldrListToArray($F_list, 0)
    For $I = 1 To UBound($Flist) - 1
        $targetDir = $Flist[$I]
        MsgBox(0, "", $targetDir)
        $aZipList = _FileListToArray($targetDir, "*.zip", 1);<-- last param changed to 1 so we only get files (unlikely to make any difference
        If IsArray($aZipList) Then
            For $J = 1 To UBound($aZipList) - 1
                _Extract($targetDir & $aZipList[$J]);calls the extract function to extract the data from the zip files
            Next
        EndIf

    Next
    Return $aZipList
EndFunc  ;==>_Rename

Don't put too much faith in it because it's just a quick change, but I think it's nearer the way it should be than what you had.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hey...

I will explain what i'm trying to do..

There is an INPUT box...Which will only ever contain 1 zip file in the form of WEEKLY22042008.zip (the data will change each week as the zip is an update)..Once the file is copied to the INPUT folder I can then run the code which will rename the zip file to DATA_PARENT.zip and then extract the contents to EXTRCT_TEMP...The program then extracts the .zip files from EXTRCT_TEMP\ which are contained within several folders...

The extracted folders end up in the OUTPUT box.. In the form of:

OUTPUT BOX (C:\OUTPUT)

---------------

12345_789 folder

4689_00453 folder

etc, there is 10 folders in total..

UPDATE @ 16:34

--------------------

I have attached an UPDATES.zip file...I have removed 8 of the folders and made the files blank for obvious reasons..But thats how the zip file look and I need to get ahold of the data in the MASTER folders and put them in there own unique folders..

As an example...If you open the zip folder you see 2 folders...If you open 28667C_11037 you then see 463175_WU....and then if you open this folder you see the .zip file..

Then if you open the .zip file you get to the data I need, which is within the MASTER folder...

Note - The top level folders (i.e - 28667C_11037) name never changes...This is a fixed folder name....The folder within this which is 463175_WU changes on a weekly basis...Otherwise the rest is the same and the data files within MASTER.

This is one reason why I have coded it so strangely..Because I had trouble with opening the zip as the name changes, so the only solution I could think of was to rename any *.zip files so the code can easily locate the file and extract it..The INPUT will end up in program files once complete so there will never be more than 1 file as the program will clear out the folder before doing anything else...

Edited by jben
Link to comment
Share on other sites

I'm probably explaining this rather badly and making it sound complicated...To put it simply...I'm trying to create a program that will extract the MASTER folder contents (.ncp and .lcn) from the UPDATES.zip for several folders and output to a folder..

The folder name will be named according to where the license had been extracted from within the zip..So if the files have been extracted from 28667C_11037 then the folder name will be something similar..

Outcome would be that all 10 folders appear in the OUTPUT folder which include the .ncp and .lcn files relevant to the folder...

Sorry everyone for being such a pain in the butt..

This program will run from a scheduled task if i can get it working...and will check for zip files in INPUT folder...if zip is found then extract to OUTPUT and then remove original zip from INPUT..simple as that (well atleast i thought it was a few days ago haha)

Edited by jben
Link to comment
Share on other sites

I'm probably explaining this rather badly and making it sound complicated...To put it simply...I'm trying to create a program that will extract the MASTER folder contents (.ncp and .lcn) from the UPDATES.zip for several folders and output to a folder..

The folder name will be named according to where the license had been extracted from within the zip..So if the files have been extracted from 28667C_11037 then the folder name will be something similar..

Outcome would be that all 10 folders appear in the OUTPUT folder which include the .ncp and .lcn files relevant to the folder...

Sorry everyone for being such a pain in the butt..

This program will run from a scheduled task if i can get it working...and will check for zip files in INPUT folder...if zip is found then extract to OUTPUT and then remove original zip from INPUT..simple as that (well atleast i thought it was a few days ago haha)

before I get too engrossed, did the previous post I made have any useful effect? Or was it no help at all?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I checked your code Martin...Not really sure what its doing different to my code apart from putting a 1 on the end of the zip file when its renamed so i end up with DATA_CHILD1...

I'm trying to keep it as simple as possible as i'm currently talking with "someone" and hope I can get a resolution..I've just found the more I talk, the more I confuse people :-)

I should state..All my code as purely been designed based on anything I can piece together to get this to work..I may be going about it totally wrong..

All I need is to get the .ncp and .lcn files from all the MASTER folders and save to an OUTPUT folder in seperate folders relevant to where the files have been extracted from..

I guess the easyiest way to understand this is to look at the UPDATES.ZIP file attached to this post and extract the file to find the MASTER folder where the .lcn and .ncp files are stored, the structure is the same for all 10 folders but i've only included 2 in the UPDATES.ZIP file attached here because If I can get the basic idea together then I can obviously expand to include all the folders as they are all in the same structure within the zip file..

Edited by jben
Link to comment
Share on other sites

1 last post...Hopefully this will make some sense

1 - INPUT FOLDER <--Place WEEKLYUPDATE-DD\MM\YY.ZIP here (DD\MM\YY changes each week)

2 - Extract the zip contents then extract the following:

....C:\EXTRCT_TEMP\26704P_SERIAL_10366\*updatenumber*_WU\*updatenumber*_WU.zip\MASTER\ <--.ncp and .lcn file is what I need from here

3 - put the .ncp and .lcn in a folder within C:\Output <-- something like C:\Output\26704P_SERIAL_10366

4 - Repeat process with next folder in zip...

5 - Empty INPUT FOLDER

Note - *updatenumber* <-- this has been named this because the folder name changes each week...

and my code currently does the above mentioned (minus the fact it only works for 1 folder)..

Edited by jben
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...