Jump to content

File List to Array


Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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")

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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')

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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

  • Recently Browsing   0 members

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