Rammanan Posted March 7, 2019 Posted March 7, 2019 Hi all, Currently work on search file and copy the file to local. Below script can search and show at arraydisplay but it cannot copy. Please someone help on this $path = "C:\Program Files " $name = "123" $local = "C:\Temp" Local $aArray = _FileListToArrayRec($path, $name & ".pdf") _ArrayDisplay($aArray) For $i = 1 To $aArray[0] If StringInStr($aArray[$i], $name) Then $sFileCopy = $aArray[$i] ExitLoop EndIf Next FileCopy($sFileCopy,$local, 9)
FrancescoDiMuro Posted March 7, 2019 Posted March 7, 2019 @Rammanan Debug a little bit your code. In this case, since you want to copy just one file, you could use directly FileCopy(), without getting an array of just a file. To debug your code, use: If FunctionName = SuccessReturnValue Then ConsoleWrite("FunctionName OK!" & @CRLF) Else ConsoleWrite("FunctionName ERR: " & @error & @CRLF) ; If @error code is set EndIf Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Rammanan Posted March 7, 2019 Author Posted March 7, 2019 @FrancescoDiMuro The problem is every time it not copy same file. So i need search the file then copy. btw, i'm not understand how to use debug code.
Subz Posted March 7, 2019 Posted March 7, 2019 As $sFileCopy = FIlename.pdf, you then use the code FileCopy("Filename.pdf", "C:\Temp", 9) so it doesn't know the path to Filename.pdf. So you either: a. Modify your _FileListToArrayRec(..) function to include the file path, see last parameter Or use b. $sFileCopy = $path & "\" & $aArray[$] Unfortunately FileCopy doesn't have any error codes but you could use something like: #include <Array.au3> #include <File.au3> Local $bDebug = True Local $sFileCopy, $sFileName = "123" Local $sSourceDir = "C:\Program Files\" ;~ Note added end backslash "\" Local $sTargetDir = "C:\Temp\" ;~ Note added end backslash "\" Local $aFileNames = _FileListToArrayRec($sSourceDir, $sFileName & ".pdf", 1, 1, 0, 2) _ArrayDisplay($aFileNames) Local $iSearch = _ArraySearch($aFileNames, $sFileName, 1, 0, 0, 1) If $iSearch > -1 Then Local $sFileCopyResult = FileCopy($aFileNames[$iSearch], $sTargetDir, 9) = 0 ? "Failure" : "Success" If $bDebug Then MsgBox(4096, "FileCopy Results", "Copied: " & $aFileNames[$iSearch] & @CRLF & "To: " & $sTargetDir & @CRLF & "Result: " & $sFileCopyResult) Else If $bDebug Then MsgBox(4096, "Search Error", "Unable to find: " & $sFileName) EndIf
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now