KuroiLight,
Thank you for your assistance. I have looked up proper usage of = and := and == and tested out your code suggestion. When I ran your code, it generated an error about a } being in the wrong place. I can't make the script find the file without using the = sign for assignment. I then spent the next several hours troubleshooting and building some more test code that could be ran on any Windows system, provided the appropriate permissions exist, that demonstrates the issue.
This code below creates a folder under the root of C:\ called File_Copy_Test and then creates a sub-folder called CopyLocation. Then it creates a txt file in File_Copy_Test and generates an input box with the default entry of C:\File_Copy_Test\CopyLocation. Then, this code copies copyme.txt to the C:\File_Copy_Test\CopyLocation location and opens explorer showing the test was successful. Finally, it deletes the directory C:\File_Copy_Test and ends the script.
This code works beautifully.
Feel free to test it out.
Code: Select all
FileCreateDir, C:\File_Copy_Test
FileCreateDir, C:\File_Copy_Test\CopyLocation
FileAppend, This txt file will be moved to test this script.`n, C:\File_Copy_Test\copyme.txt
InputBox, UserInput, File Path Entry, Please input a file path., , 400,100,,,,,C:\File_Copy_Test\CopyLocation
if ErrorLevel
MsgBox, CANCEL was pressed.
else
MsgBox, You entered %UserInput%
FileCopy, C:\File_Copy_Test\copyme.txt, %UserInput%, 1
MsgBox, Windows Explorer will now open to %UserInput% and show copyme.txt after being moved to the new location.
explorerpath:= "explorer /e," "C:\File_Copy_Test\CopyLocation"
Run, %explorerpath%
Sleep, 1000
MsgBox, After clicking on OK, the files and directories used for this script will be deleted.
FileRemoveDir, C:\File_Copy_Test, 1
Sleep, 333
return
However, I am looking to have the file path found by searching for it, and then using that file path to copy a file rather than asking for the file path using an input box. The following code does virtually the same steps as the previous code, only the code that generates the input box is substituted with code that will find the file path. However, with this code, the file copy command doesn't work even though the correct file path is found for the copyme.txt file.
Code: Select all
FileCreateDir, C:\File_Copy_Test
FileCreateDir, C:\File_Copy_Test\CopyLocation
FileAppend, This txt file will be moved to test this script.`n, C:\File_Copy_Test\copyme.txt
directory = C:\File_Copy_Test
copy_directory = C:\File_Copy_Test\CopyLocation
search = copyme.txt
found =
loop, %directory%\*.*, 1, 1 ; search the library for the file to get the full path
{
if A_LoopFileName = %search%
{
found = %A_LoopFileFullPath%
}
}
if found =
{
MsgBox, File not found
}
else
{
MsgBox, Found here: %found% and this file will now be copied to %copy_directory%
FileCopy, C:\File_Copy_Test\copyme.txt, %found%, 1
Sleep, 1000
explorerpath:= "explorer /e," "C:\File_Copy_Test\CopyLocation"
Run, %explorerpath%
Sleep, 1000
MsgBox, After clicking on OK, the files and directories used for this script will be deleted.
FileRemoveDir, C:\File_Copy_Test, 1
}
Sleep, 333
return
Does that make sense? Again, please feel free to try both code segments on your system.