Jump to content

Recommended Posts

Posted

I am creating a script that will backup files and putting it into a GUI. I have found an issue and could use an explanation and possibly a way around. Here is my issue;

This code snippet work fine. It backs up all files in the target folder to the destination just fine. This include a files name that may have a space in the name.

Run(@ComSpec & " /k " & "robocopy.exe " & "C:\testUsers" & " " & "C:\_Installation\Test3 /E /B /COPYALL /W:0 /R:0");, @SystemDir) ;, @SW_HIDE)

I am using a case statement to filter out folders I do not want to backup which is working. When I use  _FileListToArray I added a test line ( $Output = _ArrayDisplay($FileList,"$FileList")) to see what is put into the array. I can see all folder were included even those with spaces. Now I want to do my backup with my array and my case statement to filter files. I use this code for that;

Run(@ComSpec & " /k " & "robocopy.exe " & "C:\testUsers\" & $FileList[$i] & " " & "C:\_Installation\Tes13\" & $FileList[$i] & "/E /B /COPYALL /W:0 /R:0")

The code work...sort of. What I am seeing is that when using the variable $FileList and folder with a space in the name is skipped. So if I have 3 folders called default, default one and default two only the folder called default is backed up.

Is there a way around this? to get the $FileList to include folder names with spaces?

Posted

Have you tried it with FileCopy()?

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

Posted

No I have not tried FileCopy() because I need to keep the NTFS security settings on the folders when I do the copy. I know robocopy with preserve the NTFS security.  

Posted

Make sure there's quotes around the path\filename of the files being copied.

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

Posted

When I put the path (variable portion) into quotes it then sees it as a absolute not a variable. How can I include the variable portion of the path in the quotes?

Posted

This is how I'd do it.

Run(@ComSpec & " /k " & "robocopy.exe " & "'C:\testUsers\" & $FileList[$i] & "' " & "'C:\_Installation\Tes13\" & $FileList[$i] & "' /E /B /COPYALL /W:0 /R:0")

 

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

Posted

That seeme dto cause several issues. For one it changed the source directory from "c:\testusers" to "C:\users) which for test purposes I am trying to acoid

 

Posted

Here is the portion of the script I am working on. I used the $Output = _ArrayDisplay($FileList,"$FileList") to verify that the folder were read into the array even with spaces and they were. I can send the output to a msg box and get the folder name if it contains a space but I cannot get the robocopy command to read the full folder name.

 

$FileList=_FileListToArray("C:\testUsers", "*", 2)
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
;$Output = _ArrayDisplay($FileList,"$FileList")

ProgressOn("Progress Bar", "Backing up files", "Working...")
For $i = 1 To $FileList[0]
   ProgressSet($i)
   Switch $FileList[$i]
      Case "Administrator"
      Case "Administrator.old"
         ;MsgBox(0, "Accounts", "Administrator Account Found")
      Case "All Users"
      Case "All Users.old"
         ;MsgBox(0, "Accounts", "All Users Account Found")
      Case "UTMBAdmin"
      Case "UTMBAdmin.old"
         ;MsgBox(0, "Accounts", "UTMBAdmin Account Found")
      Case "UTMB_Admin"
      Case "UTMB_Admin.old"
        ;MsgBox(0, "Accounts", "UTMB_Admin Account Found")
      Case "UTMB_A~1"
      Case "UTMB_A~1.old"
         ;MsgBox(0, "Accounts", "UTMB_A~1 Account Found")
      Case "Public"
      Case "Public.old"
         ;MsgBox(0, "Accounts", "Public Account Found")
      Case "Default"
      Case "Default.old"
      Case "Default.migrated"
      Case "Default.migrated.old"
         ;MsgBox(0, "Accounts", "Default Account Found")
      Case "Default User"
      Case "Default User.old"
         ;MsgBox(0, "Accounts", "Default Account Found")
      Case "LocalService"
      Case "LocalService.old"
         ;MsgBox(0, "Accounts", "LocalService Account Found")
      Case "NetworkService"
      Case "NetworkService.old"
         ;MsgBox(0, "Accounts", "NetworkService Account Found")
      Case @UserName
         ;MsgBox(0, "Accounts", @UserName & " Account Found")
      Case Else
         $Profile = $FileList[$i]
         Run(@ComSpec & " /k " & "robocopy.exe " & "C:\testUsers\" & $FileList[$i] & " " & "C:\_Installation\Tes13\" & $FileList[$i] & " /E /B /COPYALL /W:0 /R:0")

Posted

You have failed at copy/paste. That's NOT the command line I gave you for the Run command.

49 minutes ago, wsc77320 said:

For one it changed the source directory from "c:\testusers" to "C:\users)

That is impossible.

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

Posted

As BrewManNH said you need to use combination of single and double quotes personally I would have done it the other way around to BrewManNH:D as single quotes will cause the command to modify the command line.

RunWait(@ComSpec & ' /k robocopy.exe "C:\testUsers\' & $FileList[$i] & '" "C:\_Installation\Tes13\' & $FileList[$i] & '" /E /B /COPYALL /W:0 /R:0')

 

Posted

The first suggestion;

Run(@ComSpec & " /k " & "robocopy.exe " & "'C:\testUsers\" & $FileList[$i] & "' " & "'C:\_Installation\Tes13\" & $FileList[$i] & "' /E /B /COPYALL /W:0 /R:0")

Here are 2 screen shots;

Code: Run(@ComSpec & " /k " & "robocopy.exe " & "'C:\testUsers\" & $FileList[$i] & "' " & "'C:\_Installation\Tes13\" & $FileList[$i] & "' /E /B /COPYALL /W:0 /R:0")

Original.thumb.JPG.358ac3211c6aa12fbc4f7323e9d2a0fb.JPG

Notice the source path. Also it did copy folders like I wanted but still missed the folder with a space in the name

This is with the suggested code;Suggested_Code.thumb.JPG.17d7696445fe3712b55acc4bbd3da417.JPG

Notice the different source path. So you can stress that it is NOT possible but HERE is proof that is it not only possible but it actually did happen. 

 

Subz thank you you method worked. I apparently was just placing my quotes in the wrong place. 

Posted (edited)

For clarification or simplification
A good practice is to add Escape sequences aka: (\) to quotes around paths when using @ComSpec Especially so robocopy.exe can acknowledge them properly
So quotes within autoit's will look Like:  '\"'

Example (not tested)

$sParm = ' /E /B /COPYALL /W:0 /R:0'
RunWait(@ComSpec & ' /k robocopy.exe \"' & $sPath & '\" \"' & $sDest & '\"' & $sParm

Edit:

Breaking it more like:

RunWait(@ComSpec & ' /k ' & 'robocopy.exe' & ' \"' & $path & '\" \"' & $sDest & '\"' & $sParm)

 

Edited by Deye
Posted

The second output could not come from the command line posted, your source can not be set that way by what's written in the command. Post the exact run command that gave you the output in the second screenshot.

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

Posted

@BrewManNH when you use single quote it modifies the command line with the current directory, so for example:

C:\WINDOWS\system32>RoboCopy 'C:\Something' 'D:\Something'

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Friday, 13 April 2018 2:12:19 AM
   Source : C:\WINDOWS\system32\'C:\Something'\
     Dest : C:\WINDOWS\system32\'D:\Something'\

    Files : *.*

  Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

 

Posted

Must be a Robocopy bug.

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

Posted

Oops, Sorry my bad.
Just remembered that the example syntax I have posted is for working with a  "powershell.exe -command ." Passes not @ComSpec
So again,

for the simple course:

RunWait(@ComSpec & ' /k robocopy.exe "' & $sPath & '" "' & $sDest & '"' & $sParm)

 

Posted
Run(@ComSpec & " /k " & "robocopy.exe " & "'C:\testUsers\" & $FileList[$i] & "' " & "'C:\_Installation\Tes13\" & $FileList[$i] & "' /E /B /COPYALL /W:0 /R:0")

 

this is the code that caused the strange path change. I am not sure why it did because c:\users is not even in the command. It was a strange outcome that was not expected.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...