muncherw Posted January 18, 2012 Posted January 18, 2012 (edited) I'm trying to move the files from one directory into another based on their timestamp. If I run this from the source directory and use FileFindFirstFile("*.dss") it works. If I change that to a path, it returns a 1 which seems good but then the $t = FileGetTime($file, 0) line doesn't work. I don't understand what is going on here. I've read a bunch of FileFindFirst File topics but don't see how mine is different. I want to have the source path in there because a user need to run it and I don't want to run the risk of her moving it out of the directory and suddenly moving all sorts of files from her desktop or wherever into the folders on the server. $sourcePath = "\\Dictations\Backups\Backup\" $destinationPath = "\\Dictations\Backups\FolderA\" $search = FileFindFirstFile($sourcePath & "*.dss") ;;Everything works fine if this is "*.dss" If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop ;Get the date of the source file which will be the destination folder name $t = FileGetTime($file, 0) If Not @error Then $yyyymd = $t[0] & $t[1]& $t[2] Else MsgBox(0, "Error", "Can't get the date") EndIf ;See if destination folder exsists, create folder if it doesn't If FileExists($destinationPath & $yyyymd) Then Else ;MsgBox(4096,"Creating dir" , "Creating directory \\Dictations\Backups\FolderA\" & $yyyymd) DirCreate($destinationPath & $yyyymd) EndIf ; See if the file exists at destination, if not then move it there If FileExists($destinationPath & $yyyymd & "\" & $file) Then Else ;MsgBox(4096,"Copying" , "Copying " & $file & " to \FolderA\" & $yyyymd) FileMove($file, $destinationPath& $yyyymd & "\" & $file) EndIf WEnd ; Close the search handle FileClose($search) Edited January 18, 2012 by muncherw Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Moderators Melba23 Posted January 18, 2012 Moderators Posted January 18, 2012 muncherw,I always wonder why people insist on using FileFindFirst/NextFile when there is a perfectly good function which makes everything so simple - _FileListToArray. This works for me when I use your paths on my machine - see if it does for you: #include <File.au3> $sSourcePath = "DictationsBackupsBackup" $sDestinationPath = "DictationsBackupsFolderA" ; Get a list of .dss files $aList = _FileListToArray($sSourcePath, "*.dss", 1) ; Are there any files? If @error then MsgBox(0, "Error", "No files matched the search pattern") Else ; Loop through the found files For $i = 1 To $aList[0] ; Get the date $aDTG = FileGetTime($aList[$i]) If @error Then MsgBox(0, "Error", "Cannot read the date for " & $aList[$i]) Else ; ; Set date string $sDate = $aDTG[0] & $aDTG[1] & $aDTG[2] ; Does folder exist? If Not FileExists($sDestinationPath & $sDate) Then ; Note use of "Not" ; Create folder if not DirCreate($sDestinationPath & $sDate) EndIf ; Check if file exists in folder If Not FileExists($sDestinationPath & $sDate & "" & $aList[$i]) Then ; Move file if it does not FileMove($sSourcePath & $aList[$i], $sDestinationPath & $sDate & "" & $aList[$i]) EndIf EndIf Next EndIfPlease ask if anything is unclear - or does not work. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
muncherw Posted January 18, 2012 Author Posted January 18, 2012 Thanks, Melba23. it doesn't work. The files in $aList are correct but it errors on FileGetTime() still. Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Moderators Melba23 Posted January 18, 2012 Moderators Posted January 18, 2012 muncherw,Try changing the FileGetTime line to read:FileGetTime($sSourcePath & $aList[$i])I was running the script from the source folder so I did not need a path - you probably do. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
muncherw Posted January 18, 2012 Author Posted January 18, 2012 Oh, yeah! That did the trick. Thanks a bunch. Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
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