StOngeCompany Posted May 24, 2012 Share Posted May 24, 2012 Hello AutoIt Forums, I'm working on a script that will scan a directory and zip every file ending in .accdb. I have a working script, but I want it to include subfolders too. Here is what I have so far: $directory = InputBox ("Directory", "Please enter the directory.") $accdb = FileFindFirstFile($directory & "\" & "*.accdb") If $accdb = -1 Then MsgBox(0, "Error", "There are no databases in that directory.") Exit EndIf While 1 Local $file = FileFindNextFile($accdb) If @error Then ExitLoop DirCreate($directory & "\" & "Databases") FileMove($directory & "\" & "*.accdb", $directory & "\" & "Databases") WEnd RunWait('Winzip32.exe -a "C:\Users\dberndt\Desktop\Test\Databases.zip" "C:\Users\dberndt\Desktop\Test\Databases"') DirRemove($directory & "\" & "Databases", 1) FileClose($accdb) The script puts all .accdb files into a single folder and then zips that folder. Now I need it to also scan subfolders. I understand the purpose of this forum isn't to simply supply me with a debug, but I'm stumped on where to go from here. I'd be very grateful if anyone here can at least point me in the right direction. Thank you in advance very much for your time and effort. Link to comment Share on other sites More sharing options...
Spiff59 Posted May 24, 2012 Share Posted May 24, 2012 There are a ton of recursive _FileListToArray() functions in the Examples forum that will work for you. Link to comment Share on other sites More sharing options...
Mechaflash Posted May 24, 2012 Share Posted May 24, 2012 Is there more than 1 level of subfolders? Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Zedna Posted May 24, 2012 Share Posted May 24, 2012 There is also _FileListToArrayEx() ... Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 25, 2012 Moderators Share Posted May 25, 2012 StOngeCompany,Try the RecFileListToArray UDF in my sig. 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 Link to comment Share on other sites More sharing options...
StOngeCompany Posted May 31, 2012 Author Share Posted May 31, 2012 Melba23,Thank you for the quick response. The RecFileListToArray UDF is great! I have one further question though. I am able to capture all of the .accdb files, including subfolders, but how do I move them into a new folder?Here is my script:#include <Array.au3> #include "RecFileListToArray.au3" $directory = InputBox ("Directory", "Please enter the directory.") $accdb = _RecFileListToArray($directory & "", "*.accdb", 0, 1, 1) ConsoleWrite("Error: " & @error & " - " & " Extended: " & @extended & @CRLF) _ArrayDisplay($accdb, ".accdb Files")Say I wanted to move all of the files in the $accdb array to a new directory, how would I do that?I tried the following with no luck:DirCreate($directory & "" & "Databases") FileMove($accdb, $directory & "" & "Databases")Do you have any suggestions? Thank you very much. Link to comment Share on other sites More sharing options...
Mechaflash Posted May 31, 2012 Share Posted May 31, 2012 Iterate over the file list in the array. If the [0] index is just the total files, you'll want to skip the first iteration, or if you have no need for the file total, just delete it. So after your code: $sTarget = $directory & "Databases" $iSkip = 0 For $file in $accdb If IsInt($accdb[0]) And $iSkip = 0 Then $iSkip+=1 else FileMove($file, $sTarget, 8) ; use 9 switch instead of 8 if you want to overwrite files as well. endif Next Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
StOngeCompany Posted May 31, 2012 Author Share Posted May 31, 2012 mechaflash213, thank you so much for your help. I believe I am very close now. The commands you added create the Database folder successfully, and are pulling all of the .accdb's correctly, but they are still not moving into the Databases folder. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 31, 2012 Share Posted May 31, 2012 You have to add the $ReturnPath parameter and set it to 2 in the RecFileListToArray function, otherwise the function returns the file name only with no path information, and you can't move the file by just the file name, you need the source directory it is coming from. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Mechaflash Posted May 31, 2012 Share Posted May 31, 2012 (edited) Change the $iReturnPath argument to 2 in your RecFileListToArray as the default (1) only grabs relative paths and not full paths to the files. EDIT: Gah Brew beat me by 1/2 a second =D Edited May 31, 2012 by mechaflash213 Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” 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