Link to home
Start Free TrialLog in
Avatar of Mugiwara Yanko
Mugiwara YankoFlag for Japan

asked on

PS script requirement for processing zip files.

Hi Experts,


Sorry this is a bit long read, 


I have the following requirement, which I m dividing into a few parts for a better understanding. 


1. Pick the oldest .zip file 

2. Unzip it

3. Perform CRLF operations on those files and move them to a different folder. 

4. Now zip the .dsv files into a folder and then move that zip file to a different folder.



1.  Picking the oldest zip file, the below script does pick the oldest zip file. Ignore the unwanted parts from the below script.


$filePattern = '*.zip'  #source and destination folders
$timestampPattern = '_(?<Timestamp>\d{6}_\d\d_\d\d_\d\d)$'
$dtFormat = 'MMddyy_HH_mm_ss'
 
Try {


               $zipItems = Get-ChildItem -LiteralPath $inFolder -Filter $filePattern -File |


                              Where-Object {$_.BaseName -match $timestampPattern} |


                              Select-Object -Property Name, BaseName, FullName, @{n='Timestamp'; e={[DateTime]::ParseExact($Matches['Timestamp'], $dtFormat, $null)}}, LastWriteTime


               $zipItem = $zipItems |


                              Sort-Object -Property Timestamp |        


                              Select-Object -First 1  # this picks the oldest date first

Open in new window



2. Need a script for unarchiving them to a folder 


Expand-Archive -Path $zipItem.FullName -DestinationPath $outFolder -Force -Verbose -ErrorAction Stop

Open in new window


3. CRLF on those .dsv files 


I already have these CRLF scripts, I have to call those 14 different scripts in this script. 


4. Now zip the .dsv files into a folder and then move that zip file to a different folder.


I need to zip the CRLF-processed files(in a folder) to be archived and then move them to a different folder. Here we need to give the zip file name the same as the file picked from step 1


We need to implement all these in a single script. 



The above scripts are provided by oBdA san. 

SOLUTION
Avatar of dfke
dfke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mugiwara Yanko

ASKER

$tmpPath  this has the CRLF processed files I need to archive  these processed files into a different folder 


Compress-Archive -Path "$($dsvFolder)\*.dsv" -DestinationPath "$($outFolder)\$($zipItem.Name)" -Force 


for this part ?? 

Avatar of oBdA
oBdA

$tempPath is a temporary path that is used while the original file is still being processed; it's not relevant.
The Compress-Archive command takes all the processed files, and puts them into an archive with the same name as the original archive, stored in the folder you defined in $outFolder.

Okay got it thanks oBdA-san