tfehring Posted November 15, 2013 Share Posted November 15, 2013 Or, "I cobbled this together last night and it seems like it should work but it doesn't." The intended purpose is to check the Downloads directory for music or video files (or subfolders that contain them) and move either the files themselves or the folders containing them to the appropriate directories, keeping the same hierarchy in the destination folder if applicable. I realize that it shouldn't work at this point if the media files are more than one subdirectory deep, but I'll extend my script to handle that once I've got it working in the simpler case. Right now, if I run the script, the tray icon just flashes briefly (kinda makes it hard to tray debug) and nothing happens with the test files I have in the downloads directory. Any help would be appreciated. Thanks in advance! expandcollapse popup$mainPath = "D:\Downloads" $copyPathMusic = "D:\Music" $copyPathVideo = "D:\Videos" $firstSearch = FileFindFirstFile($mainPath&"\*") If $firstSearch <> -1 Then While 1 $firstFile = FileFindNextFile($firstSearch) If @error Then Exit ;Note that incomplete downloads get stored in Downloads\Pending ElseIf @extended And $firstFile <> "Pending" Then $secondSearch = FileFindFirstFile($firstFile&"\*") If $secondSearch <> -1 Then While 1 $secondFile = FileFindNextFile($secondSearch) If $secondFile = "*.mp3" Or $secondFile = "*.wma" Or $secondFile = "*.flac" Then If DirCopy($mainPath&"\"&$firstFile,$copyPathMusic"\"&$firstFile) = 1 Then DirRemove($mainPath&"\"&$firstFile,1) EndIf ElseIf $secondFile = "*.mp4" Or $secondFile = "*.avi" Or $secondFile = "*.mpg" Or $secondFile = "*.wmv" Or $secondFile = "*.mov" Or $secondFile = "*.m4v" Or $secondFile = "*.flv" Then If DirCopy($mainPath&"\"&$firstFile,$copyPathVideo"\"&$firstFile) = 1 Then DirRemove($mainPath&"\"&$firstFile,1) EndIf EndIf WEnd EndIf ElseIf Not @extended Then If $firstFile = "*.mp3" Or $secondFile = "*.wma" Or $secondFile = "*.flac" Then If FileCopy($mainPath&"\"&$firstFile,$copyPathMusic"\"&$firstFile) = 1 Then FileDelete($mainPath&"\"&$firstFile) EndIf ElseIf $firstFile = "*.mp4" Or $secondFile = "*.avi" Or $secondFile = "*.mpg" Or $secondFile = "*.wmv" Or $secondFile = "*.mov" Or $secondFile = "*.m4v" Or $secondFile = "*.flv" Then If FileCopy($mainPath&"\"&$firstFile,$copyPathVideo"\"&$firstFile) = 1 Then FileDelete($mainPath&"\"&$firstFile) EndIf EndIf EndIf WEnd Else Exit EndIf Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 15, 2013 Moderators Share Posted November 15, 2013 tfehring,I have a real aversion to debugging FileFindFirst/NextFile scripts when there are functions within AutoIt to do all the donkey work for you. If the England game tonight is not too interesting I will work on an example for you - if it is a good match you may have to wait until tomorrow! M23 mLipok 1 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 Link to comment Share on other sites More sharing options...
ravaged1 Posted November 15, 2013 Share Posted November 15, 2013 You might want to just use robocopy. Link to comment Share on other sites More sharing options...
mrider Posted November 15, 2013 Share Posted November 15, 2013 As posted, lines 17, 21, 29, and 33 are all missing an ampersand ("&"). My ampersands are red where yours are missing... Line 17: If DirCopy($mainPath&""&$firstFile,$copyPathMusic&"" Line 21: If DirCopy($mainPath&""&$firstFile,$copyPathVideo&"" Line 29: If FileCopy($mainPath&""&$firstFile,$copyPathMusic&"" Line 33: If FileCopy($mainPath&""&$firstFile,$copyPathVideo&"" Is this code exactly what you are running? You might consider running your code from inside SciTE in the future, the console will point out the exact issues. How's my riding? Dial 1-800-Wait-There Trying to use a computer with McAfee installed is like trying to read a book at a rock concert. Link to comment Share on other sites More sharing options...
tfehring Posted November 15, 2013 Author Share Posted November 15, 2013 tfehring, I have a real aversion to debugging FileFindFirst/NextFile scripts when there are functions within AutoIt to do all the donkey work for you. If the England game tonight is not too interesting I will work on an example for you - if it is a good match you may have to wait until tomorrow! M23 Yeah, I'm new to AutoIt (I've successfully written one script, and that was months ago and with a completely different purpose) and I dislike them already. I just Googled applications similar to the one I'm going for, and they came up often and seemed like they'd fit reasonably well. Meh. You might want to just use robocopy. Wouldn't I still need to use FileFindFirst/NextFile or something similar to check the file types though? I mean... robocopy $mainPath&"\"&$subdirectory" $copyPathMusic&"\"&$subdirectory /mov would (should?) work the same as the copying functions I have now, but I still need to check the file extension to determine whether to move to $copyPathMusic or $copyPathVideo. I can't just use /xf *.avi *.mpg *.wmv *.mov *.m4v *.flv (or whatever the correct syntax for that would look like) because there's also the possibility of folders that contain neither music nor videos, which I just want to keep in D:Downloads. And I can't imagine /xf Not *.mp3 Not *.wma Not *.flac (again, just pretend I didn't butcher the syntax ) would really work either. Link to comment Share on other sites More sharing options...
tfehring Posted November 15, 2013 Author Share Posted November 15, 2013 As posted, lines 17, 21, 29, and 33 are all missing an ampersand ("&"). My ampersands are red where yours are missing... Line 17: If DirCopy($mainPath&""&$firstFile,$copyPathMusic&"" Line 21: If DirCopy($mainPath&""&$firstFile,$copyPathVideo&"" Line 29: If FileCopy($mainPath&""&$firstFile,$copyPathMusic&"" Line 33: If FileCopy($mainPath&""&$firstFile,$copyPathVideo&"" Is this code exactly what you are running? You might consider running your code from inside SciTE in the future, the console will point out the exact issues. I can't believe I missed that, though I added the ampersands and it didn't seem to make a difference. But yes, this is exactly what I'm running, other than the fact that I added the operator for tray icon debugging. This probably isn't the root of the problem, but the @extended flags just show up in black in the editor, while @error shows up in pink. Anything wrong with my syntax there? Link to comment Share on other sites More sharing options...
kylomas Posted November 15, 2013 Share Posted November 15, 2013 (edited) tfehring, Perhaps I can save M23 some trouble. First you need the "RecFileListToArray" UDF which can be downloaded from >here. Once you have the UDF you can use a construct like the following to move your files... #include <recfilelisttoarray.au3> #include <array.au3> local $lPath = 'c:\users\admin010\downloads' ; my DL folder, change to yours, obviously local $fl_type ; will contain file extention from SRE $aArray = _RecFileListToArray($lPath, "*",1,1) ; lists all files in $lPath and subfolders ;_arraydisplay($aArray) ; display the array of downloaded files for $1 = 0 to ubound($aArray) - 1 ; loop through every file $fl_type = stringregexpreplace($aArray[$1],'.*\.(.*)','$1') ; set $fl_type to the file extention switch $fl_type ; if file extention is... case 'mp3', 'wma', 'flac' ; one of these then... ; ; do your move to music routine ; case 'mp4', 'avi', 'mpg', 'wmv', 'mov', 'm4v', 'flv' ; or one of these then... ; ; do your movie move routine ; endswitch Next kylomas edit: additional info You can get the file name (minus path) like this $fl_name = stringregexpreplace($aArray[$1],'.*\\(.*)','$1') ; set $fl_name to the file name Edited November 15, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
ravaged1 Posted November 15, 2013 Share Posted November 15, 2013 (edited) Wouldn't I still need to use FileFindFirst/NextFile or something similar to check the file types though? Sorry, Robocopy has nothing to do with Autoit at all, though you could call it from an Autoit script. Robocopy (the name is short for Robust File Copy) was introduced with the Windows Server 2003 Resource Kit and is included in all editions of Windows 7 Just open a cmd prompt and type robocopy /? Then make a batch file to move the files you want. Edited November 15, 2013 by ravaged1 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