Jump to content

Failed to Copy Folder


gahhon
 Share

Recommended Posts

I would like to copy the entire folder with current directory @WorkingDir

paste into either Program Files or Program Files (x86)

Global Const $CUR_WA_FOLDER         = @WorkingDir     & "\Test Folder"
Global Const $DIR_FOLDER            = _ProgramFilesDir()

_Initial_Check()

Func _Initial_Check()
    If FileExists($DIR_FOLDER & "\Test Folder") = 0 Then
        Local $Decisions = _Metro_MsgBox(4, "", "Do you want to install Test Application?")
        If $Decisions = "Yes" Then
            DirCopy($CUR_WA_FOLDER, $DIR_FOLDER, 1)
        Else
            _Close_Application()
        EndIf
    EndIf
EndFunc

Func _ProgramFilesDir()
    Local $ProgramFilesDir
    Switch @OSArch
        Case "X32"
            $ProgramFilesDir = "Program Files"
        Case "X64"
            $ProgramFilesDir = "Program Files (x86)"
    EndSwitch
    Return @HomeDrive & "\" & $ProgramFilesDir
EndFunc

 

Edited by gahhon
Link to comment
Share on other sites

So, what's your question? Is something not working as expected?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

you are not even checking the return value of DirCopy for success or Failure. show the Scite output please too if something is wrong.

this is most likely an Permissions problem, elevate to Admin and try it. Windows doesn't like it when you copy things to that directory usually. Installers and other things that have permissions, yes, dircopy? no.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

On 11/01/2019 at 12:45 AM, BrewManNH said:

So, what's your question? Is something not working as expected?

Sorry that I not saying the question. And yes, the folder is not copy to destination.

On 11/01/2019 at 2:26 AM, Earthshine said:

you are not even checking the return value of DirCopy for success or Failure. show the Scite output please too if something is wrong.

this is most likely an Permissions problem, elevate to Admin and try it. Windows doesn't like it when you copy things to that directory usually. Installers and other things that have permissions, yes, dircopy? no.

I have print out the return value and it is 0 which mean failed to copy.

But where can i check the error message to see what is the issue?

Link to comment
Share on other sites

57 minutes ago, gahhon said:

But why I can't copy to Program File x86 instead? Please advise

As explained above, Windows won't let you copy to the Program Files folder without running it as admin, use #RequireAdmin in your script and see if that works. 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Program folder is for programs not data hence the protection schemes that are used to protect it from unwarranted copies. 

That’s why it’s not allowed it’s a security risk. So that is why you need to elevate your script to run as an administrator

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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

×
×
  • Create New...