How do I copy files using IF/Else?

(imported topic written by SystemAdmin)

hi there,

my latest attempts failed…

This is the results of my action script. It downloaded ok but didn’t copy the file across…

Completed download http://myserver:52311/Uploads/IMPAX.lnk

Completed continue if {(size of it = 1813 and sha1 of it = “3db6315938bbfa38aae3b515a93c4c9bfa9f030f”) of file “IMPAX.lnk” of folder “__Download”}

Completed if {(exists folder “c:\localapps”)}

Completed if {(exists file “IMPAX.lnk” of folder “c:\localapps”)}

Completed delete “c:\localapps\IMPAX.lnk”

Completed copy “__Download\IMPAX.lnk” “c:\localapps”

Completed else

Failed copy “__Download\IMPAX.lnk” “c:\localapps”

endif

else

dos Mkdir “c:\localapps”

endif

action script:

download http://myserver:52311/Uploads/IMPAX.lnk

continue if {(size of it = 1813 and sha1 of it = “3db6315938bbfa38aae3b515a93c4c9bfa9f030f”) of file “IMPAX.lnk” of folder “__Download”}

if {(exists folder “c:\localapps”)}

if {(exists file “IMPAX.lnk” of folder “c:\localapps”)}

delete “c:\localapps\IMPAX.lnk”

copy “__Download\IMPAX.lnk” “c:\localapps”

else

copy “__Download\IMPAX.lnk” “c:\localapps”

endif

else

Dos Mkdir “c:\localapps”

endif

(imported comment written by BenKus)

Try putting the filename in the copy command:

if {(exists folder “c:\localapps”)}
if {(exists file “IMPAX.lnk” of folder “c:\localapps”)}
delete "c:\localapps\IMPAX.lnk"
copy “__Download\IMPAX.lnk” "c:\localapps\IMPAX.lnk"
else
copy “__Download\IMPAX.lnk” "c:\localapps\IMPAX.lnk"
endif
else
Dos Mkdir "c:\localapps"
endif

You can use the Fixlet debugger to help debug your action:

http://support.bigfix.com/fixlet/

Ben

(imported comment written by SystemAdmin)

I think the logic here is a bit convoluted because if the folder does not exist, your file would have been downloaded, but never copied into the folder. I don’t think this is what was intended.

Try this instead:

if {(exists folder “c:\localapps”)}

if {(exists file “IMPAX.lnk” of folder “c:\localapps”)}

delete “c:\localapps\IMPAX.lnk”

endif

else

Dos Mkdir “c:\localapps”

endif

copy “__Download\IMPAX.lnk” “c:\localapps\IMPAX.lnk”

(imported comment written by jessewk)

even simpler:

if {(exists file “c:\localapps\IMPAX.lnk”)}

delete “c:\localapps\IMPAX.lnk”

else

Dos Mkdir “c:\localapps”

endif

copy “__Download\IMPAX.lnk” “c:\localapps\IMPAX.lnk”

(imported comment written by SystemAdmin)

Thanks guys, that works now and is simplified as well, however the fixlet debugger doesnt work for me:

Runtime Error!

Program: L…

This application has requested the Runtime to terminate in an unusual way. Please contact the application support team for more information.

(imported comment written by SystemAdmin)

more information on the error:

“The exception unknown exception (0x40000015) occurred in the application at location 0x0052544c”

I unzipped it to 2 PCs and had the same error. The first time I just dragged the contents out to a folder and the second time I extracted and both had the same results.

(imported comment written by jessewk)

Are you including the download command? Try running the action through the console rather than the Fixlet Debugger.

(imported comment written by SystemAdmin)

No the Fixlet Debugger doesn’t go much past the initial window.