Archive: how to copy files from one dir to another with file extention.


how to copy files from one dir to another with file extention.
Hi Iam writing a Installer script what it does is ……it will copy a * .p12 files from temp to config dir



Temp and config are two different dir’s , both will have not only *.p12 ,but also another files.

Temp should only copy the *.p12 files from temp to config dir and remove old *p12 files from config dir



It will work only if we know the file name. ………Without knowing the filename how to copy only specific type of file’s from one dir to another with help of file extension.

Here am writing script, which is, not work bur I want to explain you in detail.


outfile "C:\Importcert1.exe"
section Import
StrCpy $R4 ""

loop:
IfFileExists "C:\Program Files\VistaWiz\OpenVPN\temp\*.p12" config no_config


no_config:
Strcmp $R4 "counter" endall
MessageBox MB_ICONEXCLAMATION|MB_OK \
'Could not find p12 Files In temp Dir .\
$\n "Without it you cannot run " ${APPNAMEANDVERSION}". \
$\n$\n Please Extract E-Mail Attachmet Into temp Dir Then Click Importcert Link.'
goto endForGood

doDel:
StrCpy $R4 "counter"
; KillProcDLL::KillProc "openvpn-gui.exe"
delete "C:\Program Files\VistaWiz\OpenVPN\config\*.p12"

config:
KillProcDLL::KillProc "openvpn-gui.exe"
StrCmp $R4 "" doDel
CopyFiles /SILENT "C:\Program Files\VistaWiz\OpenVPN\temp\*.p12" "C:\Program Files\VistaWiz\OpenVPN\config\*.p12"
delete "C:\Program Files\VistaWiz\OpenVPN\temp\*.p12"
goto loop

endall:
SetOutPath "C:\Program Files\VistaWiz\OpenVPN\bin\"
Exec "openvpn-gui.exe"


endForGood:
sectionend

Please help p me I really appreciate


CopyFiles /SILENT "C:\Program Files\VistaWiz\OpenVPN\temp\*.p12" "C:\Program Files\VistaWiz\OpenVPN\config"


To delete all .p12 files in the temp dir, you should use FindFirst, FindNext etc:

Function DeleteP12Files
Exch $R0
Push $R1
Push $R2
ClearErrors
FindFirst $R1 $R2 "$R0\*.p12"
Top:
IfErrors Done

Delete "$R0\$R2"

ClearErrors
FindNext $R1 $R2
Goto Top
Done:

FindClose $R1
Pop $R2
Pop $R1
Pop $R0
FunctionEnd


Then call the function like so:
Push "C:\Program Files\VistaWiz\OpenVPN\temp"
Call DeleteP12Files

This will delete all p12 files in that directory.

-Stu

Thank you very very much !