V Thrusher
asked on
bash script to unzip a file
i need a script to monitor whether any files are available in the folder (with specific name) and if its available then i need to unzip the file and rename it (specific name)
The input files are placed to folder in :"D" drive. Then this files will be unzipped manually and it will have a somename.txt & we rename this .txt file to application specific name.txt. This files will be then picked by the batch job and processed accordingly. I need a script to run once day (via task scheduler) and unzip a files and rename the .txt files in folder in D drive.
File Name: FINS.txt and FINSP.txt respectively
Rename File to: OFAC.txt and OFAC_provider.txt respectively
This files are picked by the batch job and its archived by the batch job itself. So we just need to unzip a file and rename it.
The input files are placed to folder in :"D" drive. Then this files will be unzipped manually and it will have a somename.txt & we rename this .txt file to application specific name.txt. This files will be then picked by the batch job and processed accordingly. I need a script to run once day (via task scheduler) and unzip a files and rename the .txt files in folder in D drive.
File Name: FINS.txt and FINSP.txt respectively
Rename File to: OFAC.txt and OFAC_provider.txt respectively
This files are picked by the batch job and its archived by the batch job itself. So we just need to unzip a file and rename it.
ASKER
what about renaming the extracted files to a specific name ? i'm new to batch scripting, so can you explain the above code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
after extracting the zipped, you will couple txt files. we have rename those file to a specific file name e.g
File Name: FINS.txt and FINSP.txt respectively
Rename File to: OFAC.txt and OFAC_provider.txt respectively
File Name: FINS.txt and FINSP.txt respectively
Rename File to: OFAC.txt and OFAC_provider.txt respectively
Add this to end of Marius' code, above the exit /b 0 line:
ren FINS.txt FINSP.txt
ren OFAC.txt OFAC_provider.txt
Please take a look at this function:
:: Unzip a file
:unZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.Fi
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Applic
>>%vbs% echo set FilesInZip=objShell.NameSp
>>%vbs% echo objShell.NameSpace(%1).Cop
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
I am calling it this way:
call :log "DEBUG" "Extracting the archive..."
call :unZipFile "%~dp0" "%~dp0files.zip"
call :log "DEBUG" "The archive was successfully extracted"
Good luck!