Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Copy files and folders



  • Please log in to reply
2 replies to this topic
thenasos
  • Members
  • 7 posts
  • Last active: Oct 21 2015 07:08 AM
  • Joined: 21 Aug 2014

Hi,
 
I am using help example for copying files.
It works fine if have path entered separately, but if I try to use a variable, it fails to recognise it ( if I remove the quotes "Ilegal characters used", I use quotes it tries to use "%aplankas%" rather than \\sf....

 

And I know it works outside the copy function, as the "Run, %aplankas%%RowText%" works fine.
 
I tried and failed, now I cry for help.. :}

#o::
InputBox, inputPass, Copy Current Profile,  %A_UserName%a password please, hide, 200, 130
if ErrorLevel
	return
else
 RunAs %A_UserName%a, %inputPass%, CORPx
 Run, "C:\Users\xxx\Desktop\Scripts\ClientIQ\Scripts\copy_ClientIQ_profile.bat"
 RunAs

aplankas= \\SF..\PG-59804ClientIQ$\DefaultSettings\
RowText= ""

Gui, Add, ListView, r20 w300 gMyListView Sort, Name
Loop, %aplankas%*, 2
    LV_Add("", A_LoopFileName)
LV_ModifyCol()  ; Auto-size each column to fit its contents.
Gui, Show
return

MyListView:
if A_GuiEvent = DoubleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    MsgBox , 4,, Replace "%RowText%" with new profile?
	IFMsgBox Yes
		; The following example copies all files and folders inside a folder to a different folder:
			ErrorCount := CopyFilesAndFolders("C:\Users\Public\ClientIQprofile\*.*", "\\SF..\PG-59804ClientIQ$\DefaultSettings\magic") ;Works
			ErrorCount := CopyFilesAndFolders("C:\Users\Public\ClientIQprofile\*.*", "%aplankas%%RowText%") ;Does not work
			if ErrorCount <> 0
			MsgBox %ErrorCount% files/folders could not be copied.

			CopyFilesAndFolders(SourcePattern, DestinationFolder, DoOverwrite = false)
			; Copies all files and folders matching SourcePattern into the folder named DestinationFolder and
			; returns the number of files/folders that could not be copied.
			{
				; First copy all the files (but not the folders):
				FileCopy, %SourcePattern%, %DestinationFolder%, %DoOverwrite%
				ErrorCount := ErrorLevel
				; Now copy all the folders:
				Loop, %SourcePattern%, 2  ; 2 means "retrieve folders only".
				{
					FileCopyDir, %A_LoopFileFullPath%, %DestinationFolder%\%A_LoopFileName%, %DoOverwrite%
					ErrorCount += ErrorLevel
					if ErrorLevel  ; Report each problem folder by name.
						MsgBox Could not copy %A_LoopFileFullPath% into %DestinationFolder%.
				}
				return ErrorCount
	}
		Run, %aplankas%%RowText%
		
	IFMsgBox No
		return
}
return

GuiClose:  ; Indicate that the script should exit automatically when the window is closed.
ExitApp


gilliduck
  • Members
  • 109 posts
  • Last active: Nov 09 2015 01:07 AM
  • Joined: 19 Dec 2013
✓  Best Answer
ErrorCount := CopyFilesAndFolders("C:\Users\Public\ClientIQprofile\*.*", aplankas RowText)

You had two errors within it. The first was using the "'s with the variables. With quotes around it you were passing the literal string of %aplankas% not the data contained withing the variable aplankas. The second was the %'s. Using them in an expression (something that starts with :=) means you were trying to pass the data of the variable contained within the variable aplankas basically.

 

So the above should work in theory.



thenasos
  • Members
  • 7 posts
  • Last active: Oct 21 2015 07:08 AM
  • Joined: 21 Aug 2014

Yep, that worked now.

Thank you for delivering me from darkness.  B)