Anthony Padgett

FileCopy will not copy a file when using variables...

6 posts in this topic

Hello Experts,

I am trying to create a script that will go onto my network and copy a word document to a local folder then open it. When I hard code the FileCopy, it works perfectly, but when I use variables for file path and file name, only the local folder I need gets created. I cannot seem to get the file to open even when using the hard coded path in function FileOpen code. Here is my code with comments on what is happening.

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

$ProductName = "Microsoft Word 2013"
$AbvLanguage = "ENG"

$Network = "mynetwork"
$Folder = "shared"
$SampleDocs = "Sample Documents"

$DocumentName = "Holiday Schedule.docx"

$FileLocation = "mynetwork\shared\Sample Documents"


SampleDocument ()
Func SampleDocument()

;This commented out hard coded line of code below works and does the copy, create local folder, and paste
;FileCopy ("\\mynetwork\shared\Sample Documents\Microsoft Word 2013\ENG\Holiday Schedule.docx","c:\Sample Documents\",8)

;The opening of FileOpen line of code below has not worked yet, even when the file copy works
FileOpen ("C:\Sample Documents\Holiday Schedule.docx")


;Here are the 2 versions of FileCopy code(I only need one, one that works) and 1 version of FileOpen code I want to use with variables that has not work, ever

;FileCopy ("\\$Network\$Folder\$SampleDocs\$ProductName\$AbvLanguage\$DocumentName","c:\Sample Documents\",8)
;FileCopy ("\\$FileLocation\$ProductName\$AbvLanguage\$DocumentName","c:\Sample Documents\",8)
;FileOpen ("c:\$SampleDocs\$DocumentName")


What am I missing here? Is this as simple as you cannot use variables to create file paths in the FileCopy function?

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)

I followed your suggestion but it is telling me its an Unterminated String. I feel like there should be a quote mark after DocumentName but that doesnt fix it either. 

When I run the following;

FileCopy ("\\" & $Network & "\" & $Folder & "\" & $SampleDocs & "\" & $ProductName & "\" & $AbvLanguage & "\" $DocumentName,"c:\Sample Documents",8)

I get the Error: Badly Formated Variable Or Macro

I did use the code where network path was a variable and that worked. Dont know what the difference was but it worked.

FileCopy ("\\" & $FileLocation & "\" & $ProductName & "\" & $AbvLanguage & "\" & $DocumentName,"c:\Sample Documents\",8)


Maybe there is a limit to the amount of variables allowed in a string, though I doubt that.

Edited by Anthony Padgett

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

I was able to get both of them to work actually. I just retyped the code. Must be a space or something I cant see in there.


Thank you!


Now how do I get this file to open in its associated program like a double click...

Edited by Anthony Padgett

Share this post

Link to post
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

  • Similar Content

    • PINTO1927
      By PINTO1927
      Hello guys,
      I'm working on this script:
      Case $BTN Global $URL = FileOpenDialog("IMPORT FILE", $DESKTOP, "ALL FORMAT (*)", 4) $DIR_DEST = "C:\DIR-WORK\list\IMPORT_DOC\" DirCreate($DIR_DEST) Local $LINE For $t = 1 To $URL[0] _FileReadToArray($URL[$t], $LINE) For $u = 1 To $LINE[0] FileCopy($URL[$u], $DIR_DEST) Next Next the selected files via OpenFileDialog must be copied to the folder $DIR_DEST.
    • cheeroke
      By cheeroke
      OK, so i run out of ideas how to make this working. Basically my FIleCOpy statement doesn't do it job. I must be missing something. Here is my code:
      #RequireAdmin . . Local $fTasks = "C:\Drivers\Other\Tasks\" Local $fTasksSys = "C:\2\" . . . FileCopy(GUICtrlRead($fTasks) & "Win10_CNC_Setup", $fTasksSys, 8) MsgBox(0, "Boot Setting", "Copied Tasks." & $fTasks & "Win10_CNC_Setup" & @CR & "To " & $fTasksSys) FileDelete($fTasksSys & "ADxLR5_StartUp") MsgBox(0, "Boot Setting", "Deleted tasks.") while it is finally creating folder called "2" it does not want to copy files. Files are .xml but without extension one of the is called: "Win10_CNC_Setup".
      Another thing is I don't understand why this
      $FC_OVERWRITE + $FC_CREATEPATH doesn't work but if i replace it with this
      8 it does create folder.
      Main question is - how to make it copying files?
      Please help.
    • ur
      By ur
      $RootDir = "C:\x86\" $BinariesFolder = "C:\Binaries\x86\0717-15.Binary.r9642_Release_win32_Fresh" $DestinationFolder = $RootDir & "_AppFiles-Telos" $SourceFolder=$BinariesFolder FileCopy($SourceFolder & "\*.*", $DestinationFolder & "\", $FC_OVERWRITE + $FC_CREATEPATH) In the above code, even if I keep $FC_OVERWRITE, the existing files are not getting replaced.
      Any suggestion please.
    • Wicked_Caty
      By Wicked_Caty
      I'm writing a small program for creating a backup. I want to do that by using FileCopy. Everything from drive C should be copied to drive D.
      FileCopy("C:", "D:", $FC_OVERWRITE + $FC_CREATEPATH) That doesn't do anything, though. I played a bit with the paths, but nothing does what I want. Sometimes only the folder of the program itself is copied, sometimes nothing is copied.
      What am I doing wrong? What do I have to do that everything from C goes to D? Thanks!
      Edit: DirCopy does pretty much the same
    • satanico64
      By satanico64
      Hi from Bordeaux, France ! how are you today ?
      I had a problem with filecopy function.
      I have a folder with my gifs on a network folder. At the start of my program, i want to make a copy on local pc. Not much complicated.
      If i do :
      FileCopy(SOURCE ,DESTINATION, $FC_CREATEPATH) It does'nt work. My destination folder is not empty and contains file which are even present in the source. I would like that filecopy add new file from the source to the destination, without overwrite. But it does'nt work.
      If i do:
      FileCopy(SOURCE ,DESTINATION, $FC_OVERWRITE+ $FC_CREATEPATH) This overwrite with all files.
      So i do that, because it works...but if i only want to copy new file how can i do ?
      CopierDossierImage() Func CopierDossierImage() $DossierImagesReseau = "\\sw3308\IntranetSTC\Hors Web\Logiciels STC\Barre STC\images\" $DossierImagesLocal = $DossierBarreSTC & "\Images\" FileCopy($DossierImagesReseau & "*.*", $DossierImagesLocal, $FC_OVERWRITE+ $FC_CREATEPATH) EndFunc ;==>CopierDossierImage