Chimaera Posted January 14, 2012 Share Posted January 14, 2012 (edited) Ok prob a simple one but i made an array like this expandcollapse popup#include <Date.au3> Global $sFoundFiles Local $aArray = DriveGetDrive("REMOVABLE") If @error Then MsgBox(4096, "Drive Error", "No Drives Available." & @CRLF & @CRLF & _ "Please Insert Drive") Else For $i = 1 To $aArray[0] $FolderList = _FolderSearch($aArray[$i] & "Dcim") ; $FolderList=_FolderSearch(@SystemDir, '', True, 125) ConsoleWrite($FolderList) If FileExists($FolderList) Then ;~ Local $files = "" ;~ For $i In $aArray ;~ $sFoundFiles = $files & $i & @CRLF ;~ Next ;~ $sFoundFiles = FileExists($aArray[$i] & "Dcim") FileCopy($sFoundFiles, @DesktopDir & "Backup " & _Date_Time_GetLocalTime(), 9) MsgBox(4096, "Drive Test" & $i, "Removable Drive " & StringUpper($aArray[$i] & "") & " Dcim Exist") Else MsgBox(4096, "Drive Test" & $i, "Removable Drive " & StringUpper($aArray[$i] & "") & " No Files Found") EndIf Next EndIf ; ============================================================================================ ; Function Name ...: _FolderSearch ; AutoIt Version ....: 3.3.2.0+ , versions below this @extended should be replaced by of StringInStr(FileGetAttrib($Path&''&$file), "D") ; Description ........: Search folders on a mask in the subdirectories. ; Syntax................: _FolderSearch($Path[, $Mask = '*' [, $Include=True [, $Depth=0 [, $Full=1 [, $Array=1]]]]]) ; Parameters: ; $Path - search path ; $Mask - mask using the characters "*" and "?" with the separator "|" ; $Include - (True / False) invert the mask, that is excluded from the search of folders ; $Depth - (0-125) nesting level (0 - root directory) ; $Full - (0,1) ; |0 - relative ; |1 - full path ; $Array - (0,1,2) if the value other than zero, the result is an array (by default ), ; |0 - a list of paths separated by @CRLF ; |1 - array, where $array[0]=number of folders ( by default) ; |2 - array, where $array[0] contains the first folder ; Return values ....: Success - Array ($array[0]=number of folders) or a list of paths separated by @CRLF ; Failure - empty string, @error: ; |0 - no error ; |1 - Invalid path ; |2 - Invalid mask ; |3 - not found ; Author(s) ..........: AZJIO ; Remarks ..........: Use function _CorrectMask if it is required correct mask, which is entered by user ; ============================================================================================ Func _FolderSearch($Path, $Mask = '*', $Include = True, $Depth = 0, $Full = 1, $Array = 1) Local $FolderList, $aFolderList, $i If $Mask = '|' Then Return SetError(2, 0, '') ; If Not StringRegExp($Path, '(?i)^[a-z]:[^/:*?"<>|]*$') Or StringInStr($Path, '') Then Return SetError(1, 0, '') If Not FileExists($Path) Then Return SetError(1, 0, '') If StringRight($Path, 1) <> '' Then $Path &= '' If $Mask = '*' Or $Mask = '' Then $FolderList = StringTrimRight(__FolderSearch($Path, $Depth), 2) Else $FolderList = StringTrimRight(__FolderSearchMask($Path, $Depth), 2) $Mask = StringReplace(StringReplace(StringRegExpReplace($Mask, '[][$^.{}()+]', '$0'), '?', '.'), '*', '.*?') If $Include Then $aFolderList = StringRegExp($FolderList, '(?mi)^(.+|(?:' & $Mask & '))(?:r|z)', 3) $FolderList = '' For $i = 0 To UBound($aFolderList) - 1 $FolderList &= $aFolderList[$i] & @CRLF Next Else $FolderList = StringRegExpReplace($FolderList & @CRLF, '(?mi)^.+|(' & $Mask & ')rn', '') EndIf $FolderList = StringReplace(StringTrimRight($FolderList, 2), '|', '') EndIf If Not $FolderList Then Return SetError(3, 0, '') If $Full = 0 Then $FolderList = StringRegExpReplace($FolderList, '(?m)^(?:.{' & StringLen($Path) & '})(.*)$', '1') Switch $Array Case 1 $FolderList = StringSplit($FolderList, @CRLF, 1) Case 2 $FolderList = StringSplit($FolderList, @CRLF, 3) EndSwitch Return $FolderList EndFunc ;==>_FolderSearch Func __FolderSearchMask($Path, $Depth, $LD = 0) Local $FolderList = '', $file, $s = FileFindFirstFile($Path & '*') If $s = -1 Then Return '' While 1 $file = FileFindNextFile($s) If @error Then ExitLoop If @extended Then If $LD < $Depth Then $FolderList &= $Path & '|' & $file & @CRLF $FolderList &= __FolderSearchMask($Path & $file & '', $Depth, $LD + 1) ElseIf $LD = $Depth Then $FolderList &= $Path & '|' & $file & @CRLF EndIf EndIf WEnd FileClose($s) Return $FolderList EndFunc ;==>__FolderSearchMask Func __FolderSearch($Path, $Depth, $LD = 0) Local $FolderList = '', $file, $s = FileFindFirstFile($Path & '*') If $s = -1 Then Return '' While 1 $file = FileFindNextFile($s) If @error Then ExitLoop If @extended Then If $LD < $Depth Then $FolderList &= $Path & $file & @CRLF $FolderList &= __FolderSearch($Path & $file & '', $Depth, $LD + 1) ElseIf $LD = $Depth Then $FolderList &= $Path & $file & @CRLF EndIf EndIf WEnd FileClose($s) Return $FolderList EndFunc ;==>__FolderSearch What im trying to do is if i stick my camera on pc it will auto copy the files into a folder on the desktop using FileCopy The items ive marked off are diff things ive been trying the latest being the FolderSearch from Azjio But i cant get it to pass the folder from the array so i can then get it to use the filecopy Edited January 14, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
JohnOne Posted January 14, 2012 Share Posted January 14, 2012 Post the foldersearch function, and FileCopy function probably wont work since $sFoundFiles = nothing. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Chimaera Posted January 14, 2012 Author Share Posted January 14, 2012 (edited) first post updated with funcion thats the issue how do i get the prensce of the folder i need into a variable for filecopy Edited January 14, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
JohnOne Posted January 14, 2012 Share Posted January 14, 2012 I would use the standard UDF _FileListToArray $aFolderList = _FileListToArray($aArray[$i],"*.*",2) For $i2 = 1 To $aFolderList[0] FileCopy($sFoundFiles, @DesktopDir & "Backup " & _Date_Time_GetLocalTime(), 9) Next AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Chimaera Posted January 14, 2012 Author Share Posted January 14, 2012 i Think ive confused myself now, this is what i have It runs but no copy #include <File.au3> #include <Date.au3> Local $aArray = DriveGetDrive("REMOVABLE") If @error Then MsgBox(4096, "Drive Error", "No Drives Available." & @CRLF & @CRLF & _ "Please Insert Drive") Else For $i = 1 To $aArray[0] If FileExists($aArray[$i] & "Dcim") Then $aFolderList = _FileListToArray($aArray[$i],"*.*",2) For $i2 = 1 To $aFolderList[0] FileCopy($aFolderList, @DesktopDir & "Backup " & _Date_Time_GetLocalTime(), 9) Next MsgBox(4096, "Drive Test" & $i, "Removable Drive " & StringUpper($aArray[$i] & "") & " Dcim Exist") Else MsgBox(4096, "Drive Test" & $i, "Removable Drive " & StringUpper($aArray[$i] & "") & " No Files Found") EndIf Next EndIf If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
JohnOne Posted January 15, 2012 Share Posted January 15, 2012 (edited) Try this FileCopy($aArray[$i] & "Dcim" & $aFolderList[$i2], @DesktopDir & "Backup " & _Date_Time_GetLocalTime(), 9) EDIT: Are you sure it is folders you want to copy? If so use DirCopy() might be best. Edited January 15, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Chimaera Posted January 15, 2012 Author Share Posted January 15, 2012 (edited) Well i need to copy the folder and all the stuff within it. Think of it as a backup for my camera, eventually ill add it to startup so whenever i plug in my camera it auto copies all the current files in the camera edit It displays the correct drive with arraydisplay but then ignores all the array stuff and jumps to the message For $i = 1 To $aDriveCheck[0] _ArrayDisplay($aDriveCheck, "FileList") ; <<<<<<<<<<<this works to here If FileExists($aDriveCheck[$i] & "Dcim") Then $aFolderList = _FileListToArray($aDriveCheck[$i], "*.*", 2) _ArrayDisplay($FolderList, "FileList") For $i2 = 1 To $aFolderList[0] FileCopy($aDriveCheck[$i] & "Dcim" & $aFolderList[$i2], @DesktopDir & "Backup " & _Date_Time_GetLocalTime(), 9) Next MsgBox(4096, "Drive Test" & $i, "Removable Drive " & StringUpper($aDriveCheck[$i] & "") & " Dcim Exist") ; <<<<<<<<<<<<This works from here Else MsgBox(4096, "Drive Test" & $i, "Removable Drive " & StringUpper($aDriveCheck[$i] & "") & " No Files Found") EndIf Next ill keep working at it back later Ps yes DirCopy will probably be better, thanks Edited January 15, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 15, 2012 Share Posted January 15, 2012 I don't think you got the destination folder right. You are missing a backslash after desktop (I assume) and _Date_Time_GetLocalTime() returns a struct, so it does nothing here.#include <Date.au3> ConsoleWrite(@DesktopDir & "Backup " & _Date_Time_GetLocalTime() & @LF)Source path is also confused. You ask _FileListToArray() for folders under $aDriveCheck[$i] and then add "\Dcim\" in the FileCopy(), so you end up with $aDriveCheck[$i] & "\Dcim\Dcim"...Fix is simple. Change to "$aFolderList = _FileListToArray($aDriveCheck[$i] & "\Dcim\, "*.*", 2)". I assumes you know what a backslash is and how it works. You can find information on what _Date_Time_GetLocalTime() does and how to use it in helpfile.Finally, remove that FileExist() and add some proper error checking for the _FileListToArray(). _FileListToArray() already checks if the file exist, no need to do it twice. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Chimaera Posted January 16, 2012 Author Share Posted January 16, 2012 (edited) I made a few changes but still not working And one other thought what if the DCIM folder is not in the same place all the time? will it still detect it? #include <Array.au3> #include <File.au3> #include <Date.au3> Global $FolderList, $i, $i2 Local $aDriveCheck = DriveGetDrive("REMOVABLE") If @error Then MsgBox(4096, "Drive Error", "No Drives Available." & @CRLF & @CRLF & _ "Please Insert Drive") Else For $i = 1 To $aDriveCheck[0] _ArrayDisplay($aDriveCheck, "DriveList") ; <<<<works to here $aFolderList = _FileListToArray($aDriveCheck[$i] & "Dcim", "*.*", 2) _ArrayDisplay($aFolderList, "FolderList") DirCopy($aFolderList, @DesktopDir & "Test Backup " & _NowDate(), 0) MsgBox(4096, "Drive Test " & $i, "Removable Drive " & StringUpper($aDriveCheck[$i] & "") & " Dcim Exist") ; works from here but thats just because its working down the list Next EndIf Edited January 16, 2012 by Chimaera If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
JohnOne Posted January 16, 2012 Share Posted January 16, 2012 DirCopy($aFolderList, @DesktopDir & "Test Backup " & _NowDate(), 0) $aFolderlist is an array. you specify no index to use. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
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