StOnge Posted February 19, 2009 Share Posted February 19, 2009 I'm trying to write a code that allows a user to input a client name and project code name. The project code name would become the name of a subfolder under the client folder, and a template of empty folders would be loaded into the project name subfolder. For example, a user enters "McDonalds" for the client, and "Mcdn" for the project code. A subfolder called "Mcdn" is automatically created in the "McDonalds" directory and a group of folders are copied into the "Mcdn" directory. I am having trouble copying the empty template of folders into the project name subfolder (or, in the above example, the 'Mcdn' subdirectory). The problem occurs when I try to run either xcopy or robocopy. Since I'm using variables for the folder names, I can't get the variables to be recognized in cmd. So, in short, how do I get cmd to recognize the variables that AutoIT recognizes? Here is my code so far: ;Gather client name and project code $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") ;Navigate to the client folder, create the project code directory, and navigate to it Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client) WinWaitActive($client) Sleep(1500) Send("!f") Sleep(1500) Send("{RIGHT}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send($code) Sleep(1500) Send("{ENTER}") Sleep(1500) WinClose($client) Sleep(1500) Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & '\' & $code) Sleep(1500) ;Copy folder structure from 1-newjob to code directory Sleep(1500) Run("ROBOCOPY L:\1-newjob D:\Test\Clients\" & $client "\" & $code "/mir") Sleep(1500) Any help would be greatly appreciated! Thank you! www.stonge.com Link to comment Share on other sites More sharing options...
JohnW Posted February 19, 2009 Share Posted February 19, 2009 (edited) I'm trying to write a code that allows a user to input a client name and project code name. The project code name would become the name of a subfolder under the client folder, and a template of empty folders would be loaded into the project name subfolder. For example, a user enters "McDonalds" for the client, and "Mcdn" for the project code. A subfolder called "Mcdn" is automatically created in the "McDonalds" directory and a group of folders are copied into the "Mcdn" directory. I am having trouble copying the empty template of folders into the project name subfolder (or, in the above example, the 'Mcdn' subdirectory). The problem occurs when I try to run either xcopy or robocopy. Since I'm using variables for the folder names, I can't get the variables to be recognized in cmd. So, in short, how do I get cmd to recognize the variables that AutoIT recognizes? Here is my code so far: ;Gather client name and project code $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") ;Navigate to the client folder, create the project code directory, and navigate to it Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client) WinWaitActive($client) Sleep(1500) Send("!f") Sleep(1500) Send("{RIGHT}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send($code) Sleep(1500) Send("{ENTER}") Sleep(1500) WinClose($client) Sleep(1500) Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & '\' & $code) Sleep(1500) ;Copy folder structure from 1-newjob to code directory Sleep(1500) Run("ROBOCOPY L:\1-newjob D:\Test\Clients\" & $client "\" & $code "/mir") Sleep(1500) Any help would be greatly appreciated! Thank you! You are using single quotes in the line '\' Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & '\' & $code) You are missing an ampersand in this line before "\" and before "\mir" Run("ROBOCOPY L:\1-newjob D:\Test\Clients\" & $client "\" & $code "/mir") John Edited February 19, 2009 by JohnW Link to comment Share on other sites More sharing options...
StOnge Posted February 19, 2009 Author Share Posted February 19, 2009 You are using single quotes in the line '\' Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & '\' & $code) You are missing an ampersand in this line before "\" and before "\mir" Run("ROBOCOPY L:\1-newjob D:\Test\Clients\" & $client "\" & $code "/mir") John I am able to create the subfolder with the project name just fine, but when it comes to running the robocopy, I get this error: www.stonge.com Link to comment Share on other sites More sharing options...
JohnW Posted February 19, 2009 Share Posted February 19, 2009 I am able to create the subfolder with the project name just fine, but when it comes to running the robocopy, I get this error: Use a form of the following code to run RoboCopy #include<Process.au3> $client = "Test1" $code = "Test2" _RunDos("robocopy c:\1-newjob c:\Test\Clients\" & $client & "\" & $code & " /mir") Link to comment Share on other sites More sharing options...
StOnge Posted February 19, 2009 Author Share Posted February 19, 2009 Use a form of the following code to run RoboCopy #include<Process.au3> $client = "Test1" $code = "Test2" _RunDos("robocopy c:\1-newjob c:\Test\Clients\" & $client & "\" & $code & " /mir") Thank you, I think I am getting closer. There is no longer an error, but nothing copies to the project code folder. What goes in the Process.au3 file and what do I put in place of Test1 and Test2? Thank you again for your help! www.stonge.com Link to comment Share on other sites More sharing options...
StOnge Posted February 19, 2009 Author Share Posted February 19, 2009 Oh, and if it helps, here is the code I am currently using: ;Gather client name and project code $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") ;Create the project directory, and navigate to it DirCreate("D:\Test\Clients\" & $client & "\" & $code) Sleep(1500) Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & "\" & $code) WinWaitActive($code) Sleep(1500) ;Copy the folder template from 1-newjob to the project directory #include<Process.au3> $client = "Test1" $code = "Test2" _RunDos("robocopy L:\1-newjob D:\Test\Clients\" & $client & "\" & $code & " /mir") www.stonge.com Link to comment Share on other sites More sharing options...
Malkey Posted February 19, 2009 Share Posted February 19, 2009 I'm trying to write a code that allows a user to input a client name and project code name. The project code name would become the name of a subfolder under the client folder, and a template of empty folders would be loaded into the project name subfolder. For example, a user enters "McDonalds" for the client, and "Mcdn" for the project code. A subfolder called "Mcdn" is automatically created in the "McDonalds" directory and a group of folders are copied into the "Mcdn" directory. I am having trouble copying the empty template of folders into the project name subfolder (or, in the above example, the 'Mcdn' subdirectory). The problem occurs when I try to run either xcopy or robocopy. Since I'm using variables for the folder names, I can't get the variables to be recognized in cmd. So, in short, how do I get cmd to recognize the variables that AutoIT recognizes? Here is my code so far: ;Gather client name and project code $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") ;Navigate to the client folder, create the project code directory, and navigate to it Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client) WinWaitActive($client) Sleep(1500) Send("!f") Sleep(1500) Send("{RIGHT}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send($code) Sleep(1500) Send("{ENTER}") Sleep(1500) WinClose($client) Sleep(1500) Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & '\' & $code) Sleep(1500) ;Copy folder structure from 1-newjob to code directory Sleep(1500) Run("ROBOCOPY L:\1-newjob D:\Test\Clients\" & $client "\" & $code "/mir") Sleep(1500) Any help would be greatly appreciated! Thank you!It may be easier with this approach. The example:- All directories are create in "C:\aTemp" directory for easy deletion when finished testing. If Windows Explorer is left open, Refresh will need to be used to show extra directories created. If FileExists("C:\aTemp") = 0 Then DirCreate("C:\aTemp") DirCreate("C:\aTemp\TemplateName") DirCreate("C:\aTemp\TemplateName\TemplateProject1") DirCreate("C:\aTemp\TemplateName\TemplateProject1\SubFolder1") DirCreate("C:\aTemp\TemplateName\TemplateProject1\SubFolder2") DirCreate("C:\aTemp\TemplateName\TemplateProject1\SubFolder3") EndIf $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") DirCopy("C:\aTemp\TemplateName", "C:\aTemp\" & $client, 1) ;Rename newly created project folder from TemplateProject1 to contents of $code variable. DirMove("C:\aTemp\" & $client & "\TemplateProject1", "C:\aTemp\" & $client & "\" & $code, 1) Link to comment Share on other sites More sharing options...
Danny35d Posted February 20, 2009 Share Posted February 20, 2009 There is no longer an error, but nothing copies to the project code folder. What goes in the Process.au3 file and what do I put in place of Test1 and Test2? Thank you again for your help!Try it $client = "Test1" $code = "Test2" RunWait(@ComSpec & ' /k robocopy "L:\1-newjob" ' & '"D:\Test\Clients\' & $client & '\' & $code & '" /mir', @ScriptDir, @SW_SHOW) It will open command prompt window which stay open after processing robocopy, so you can read any error. AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
StOnge Posted February 20, 2009 Author Share Posted February 20, 2009 (edited) Try it $client = "Test1" $code = "Test2" RunWait(@ComSpec & ' /k robocopy "L:\1-newjob" ' & '"D:\Test\Clients\' & $client & '\' & $code & '" /mir', @ScriptDir, @SW_SHOW) It will open command prompt window which stay open after processing robocopy, so you can read any error. Thank you so much! Again, I am one step closer. The project folder is created and the folders are copied into it successfully. For some reason, however, the permissions that are set in "D:\Test\Template" do not copy into the project folder. I would like the folders from the 'Template' directory to copy over to the project directory while keeping the same permissions set. Here is the code I am using: ;Gather client name and project code $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") ;Create the project directory, and navigate to it DirCreate("D:\Test\Clients\" & $client & "\" & $code) Sleep(1500) Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & "\" & $code) WinWaitActive($code) Sleep(1500) ;Copy the folder template from Template to the project directory Run(@ComSpec & ' /k robocopy /mir "D:\Test\Template" ' & '"D:\Test\Clients\' & $client & '\' & $code & '" /mir', @ScriptDir, @SW_SHOW) Am I just missing a switch in the robocopy command? I thought that '/mir' copied folders and permissions, but I could be wrong. Maybe there is a different switch for permissions? Once again, I would like to thank everyone who has contributed to assisting me! It really means a lot! Edited February 20, 2009 by StOnge www.stonge.com Link to comment Share on other sites More sharing options...
StOnge Posted February 20, 2009 Author Share Posted February 20, 2009 (edited) Hooray! It seems to working when I added the /sec switch after the /mir switch. I think it is working now! Thank you all so very much for all of your help! Here is the finished code: ;Gather client name and project code $client = InputBox("Client Name", "Please enter the name of the client.") $code = InputBox("Project Code", "Please enter the name of the project code.") ;Create the project directory, and navigate to it DirCreate("D:\Test\Clients\" & $client & "\" & $code) Sleep(1500) Run("C:\WINDOWS\EXPLORER.EXE /n,/e,D:\Test\Clients\" & $client & "\" & $code) WinWaitActive($code) Sleep(1500) ;Copy the folder template from 1-newjob to the project directory Run(@ComSpec & ' /k robocopy "D:\Test\Template" ' & '"D:\Test\Clients\' & $client & '\' & $code & '" /mir /sec', @ScriptDir, @SW_SHOW) Edited February 20, 2009 by StOnge www.stonge.com Link to comment Share on other sites More sharing options...
Danny35d Posted February 20, 2009 Share Posted February 20, 2009 Thank you so much! Again, I am one step closer. The project folder is created and the folders are copied into it successfully. For some reason, however, the permissions that are set in "D:\Test\Template" do not copy into the project folder. I would like the folders from the 'Template' directory to copy over to the project directory while keeping the same permissions set.Am I just missing a switch in the robocopy command? I thought that '/mir' copied folders and permissions, but I could be wrong. Maybe there is a different switch for permissions?If you still having problem with permission try /COPYALL switch, also add switches /r:3 /w:10. By default robocopy try to copy a file 1 million times and wait 30 seconds between tries before giving up in the event of error. AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now