Solomon Posted March 17, 2006 Share Posted March 17, 2006 Im writing a script to try to clean up My Documents, on my sisters PC. She sticks everything in "My Documents", instead of individual folders, like "pictures", "documents", etc. Anyway, Ive got the script working, with an associated .ini file, and its moving stuff OK. But, Id like to be able to have a key with multiple values, ie: [types] documents=*.doc, *.txt, *.rtf As it stands, it works fine with just a single value, but when there are multiple values, it doesnt move any of those specific files. My code up to now: Dim $docdir = InputBox("Select Directory", "Please type in the Documents directory.") IniWrite("test.ini", "test2", "documents", $docdir) Dim $picdir = InputBox("Select Directory", "Please type in the Picture directory.") IniWrite("test.ini", "test2", "pictures", $picdir) Dim $docs, $pics $docs = IniRead("test.ini", "types", "docs","ValueNotFound") FileMove($docs, $docdir) $pics = IniRead("test.ini", "types", "pics","ValueNotFound") FileMove($pics, $picdir) The .ini file is laid out so: [test2] docdir=[user input] picdir=[user input] [types] docs=*.doc, *.txt pics=*.jpg If I remove the "*.txt" the docs get moved fine. I dont really want to have a different [type] for each file extension she has, but is that what is required? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 17, 2006 Moderators Share Posted March 17, 2006 Just out of curiousity... Why not just do:[My Documents]txt= doc= rtf= jpg= etc...This would make it easier if you just wanted to store everything into an array, and call them easily, and or write them easily to the ini. That way everything has its specific place. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Solomon Posted March 17, 2006 Author Share Posted March 17, 2006 so, the ini file would be set up like: [My Documents] doc=c:\My Documents\documents folder\ txt=c:\My Documents\documents folder\ jpg=c:\My Documents\pictures folder\ Is that correct? Link to comment Share on other sites More sharing options...
Nuffilein805 Posted March 17, 2006 Share Posted March 17, 2006 (edited) have you tried $docs = stringsplit(iniread("test.ini", "types", "docs", "ValueNotFound"), ",") for $i = 1 to $docs[0] step 1 FileMove($docs[$i], $docdir) next same for the different kind of pics works if the inifile looks like [types]docs=*.doc,*.txtno space between hope this helps you btw nice idea Edited March 17, 2006 by Nuffilein805 my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 17, 2006 Moderators Share Posted March 17, 2006 so, the ini file would be set up like: [My Documents] doc=c:\My Documents\documents folder\ txt=c:\My Documents\documents folder\ jpg=c:\My Documents\pictures folder\ Is that correct?That's basically how I would do it (but maybe even in a different manner than that): I'm going to go do something real quick, and then let me see if I can give you an example of how I would set it up. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nuffilein805 Posted March 17, 2006 Share Posted March 17, 2006 @smoke: yours would look like $a = inireadsection ("test.ini", "types") for $i = 1 to $a[0][0] step 1 filemove("*."&$a[$i][0], $a[$i][1]) next guessed it right? my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 17, 2006 Moderators Share Posted March 17, 2006 @smoke: yours would look like $a = inireadsection ("test.ini", "types") for $i = 1 to $a[0][0] step 1 filemove("*."&$a[$i][0], $a[$i][1]) next guessed it right?The final move option.. yes, I'm sure that's the route I would have taken. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nuffilein805 Posted March 17, 2006 Share Posted March 17, 2006 my telepathic skills are quite high my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
Gene Posted March 17, 2006 Share Posted March 17, 2006 (edited) Im writing a [types] documents=*.doc, *.txt, *.rtf My code up to now: The .ini file is laid out so: [test2] docdir=[user input] picdir=[user input] [types] docs=*.doc, *.txt pics=*.jpg How about. . . documents=*.doc|*.txt|*.rtf $docs = IniRead("test.ini", "types", "documents","ValueNotFound") $aArray = StringSplit ( $docs, "|" ) For $i = 1 To $aArray[0] FileMove($aArray[$i], $docdir) Next Gene Edited March 17, 2006 by Gene [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 17, 2006 Moderators Share Posted March 17, 2006 (edited) Here, I was getting carried away, for what you said you were doing, I think this is how I would have attempted to start it personally:expandcollapse popup#include <file.au3> Local $Label[10], $Combo[10], $Button[10], $FolderToTidy = '' Local $ComboExt = 'All Extensions|.exe|.txt|.rtf|.doc|.bat|.dat|.ico|.ini|.bmp|.jpg|.jpeg|.gif|.png|.tif|.tiff|.dib|.psd|.p dd' $MainGUI = GUICreate('Tidy Folders', 400, 120) $Label[1] = GUICtrlCreateLabel('This will give you the option to tidy up your folders into a specific category.', 20, 10) $Label[2] = GUICtrlCreateLabel('Please choose the extension you would like to tidy', 20, 30) $Combo[1] = GUICtrlCreateCombo('', 260, 27, 100, 100) $Label[3] = GUICtrlCreateLabel('Please choose a folder you would like to tidy', 20, 55) $Button[1] = GUICtrlCreateButton(Chr(133), 240, 52, 30, 20) $Button[2] = GUICtrlCreateButton('Tidy Now', 160, 85, 80, 30) GUICtrlSetFont($Button[1], 14, 4, '', 'Arial Bold') GUICtrlSetData($Combo[1], $ComboExt) GUISetState() While 1 $MainGUI_Msg = GUIGetMsg() Select Case $MainGUI_Msg = - 3;$GUI_EVENT_CLOSE Exit Case $MainGUI_Msg = $Button[1] $FolderToTidy = FileSelectFolder('Select a folder to tidy', '') Case $MainGUI_Msg = $Button[2] $CheckGUIInfo = _CheckGUIInfo($MainGUI, $FolderToTidy, GUICtrlRead($Combo[1])) If $CheckGUIInfo == 1 Then MsgBox(64, 'Complete', 'Your ' & $FolderToTidy & ' has been tidied.') ElseIf $CheckGUIInfo == 2 Then MsgBox(64, 'Error', 'There was an error gathering information') EndIf EndSelect WEnd Func _TidyFolders($h_FilePath, $s_Mask = '*') Local $v_NULL = '', $s_FileName = '', $s_Ext = '', $h_Files = '' Local $a_NameArray, $a_MaskArray = '', $a_FileArray = '' ;Make an array of all the folder/file names $a_FileArray = _FileListToArray($h_FilePath & '\', $s_Mask) ;Create an array of file names and file extensions (keep them even) For $i_FileCount = 1 To UBound($a_FileArray) - 1 $s_PathSplit = _PathSplit($a_FileArray[$i_FileCount], $v_NULL, $v_NULL, $s_FileName, $s_Ext) If $s_PathSplit[3] <> '' And $s_PathSplit[4] <> '' And Not StringInStr($s_PathSplit[3] & $s_PathSplit[4], 'TidyFolderLog.txt') Then $a_NameArray = $a_NameArray & $s_PathSplit[3] & Chr(01) $a_MaskArray = $a_MaskArray & $s_PathSplit[4] & Chr(01) EndIf Next $a_MaskArray = StringSplit(StringTrimRight($a_MaskArray, 1), Chr(01)) $a_NameArray = StringSplit(StringTrimRight($a_NameArray, 1), Chr(01)) ;Create a log file for this folder if one doesn't exist If Not FileExists($h_FilePath & '\TidyFolderLog.txt') Then _FileCreate($h_FilePath & '\TidyFolderLog.txt') EndIf ;Create a log entry in the TidyFolderLog FileWriteLine($h_FilePath & '\TidyFolderLog.txt', _ @CRLF & 'Folder was tidied on: [' & @MON & '/' & @MDAY & '/' & @YEAR & '] at: [' & @HOUR & ':' & @MIN & ':' & @SEC & ']' & @CRLF & '---Files Tidied Were---' & @CRLF) ;Move files to the Destination folder 'Ext+_Files' For $i_ExtCount = 1 To UBound($a_MaskArray) - 1 If $a_MaskArray[$i_ExtCount] <> '' Then FileMove($h_FilePath & '\' & $a_NameArray[$i_ExtCount] & $a_MaskArray[$i_ExtCount], _ $h_FilePath & '\' & StringUpper(StringTrimLeft($a_MaskArray[$i_ExtCount], 1)) & '_Files' _ & '\' & $a_NameArray[$i_ExtCount] & $a_MaskArray[$i_ExtCount], 9) FileWriteLine($h_FilePath & '\TidyFolderLog.txt', $a_NameArray[$i_ExtCount] & $a_MaskArray[$i_ExtCount] & @CRLF) EndIf Next Return 1 EndFunc Func _CheckGUIInfo($s_HWND, $h_FilePath = '', $v_GUICtrlReadExt = '') If $h_FilePath <> '' And ($v_GUICtrlReadExt <> '' Or Not $v_GUICtrlReadExt = 'All Extensions') _ And StringInStr($v_GUICtrlReadExt, '.') Then GUISetState(@SW_HIDE, $s_HWND) If _TidyFolders($h_FilePath, '*' & $v_GUICtrlReadExt) == 1 Then GUISetState(@SW_SHOW, $s_HWND) SetError(1) Return 1 Else GUISetState(@SW_SHOW, $s_HWND) SetError(2) Return 2 EndIf ElseIf $h_FilePath <> '' And (Not $v_GUICtrlReadExt <> '' Or $v_GUICtrlReadExt = 'All Extensions') Then GUISetState(@SW_HIDE, $s_HWND) If _TidyFolders($h_FilePath) == 1 Then GUISetState(@SW_SHOW, $s_HWND) SetError(1) Return 1 Else GUISetState(@SW_SHOW, $s_HWND) SetError(2) Return 2 EndIf ElseIf (Not $v_GUICtrlReadExt <> '' And Not StringInStr($v_GUICtrlReadExt, '.')) And Not $h_FilePath <> '' Then GUISetState(@SW_HIDE, $s_HWND) MsgBox(64, 'Error', 'You did not enter the correct syntax, you need to enter like "."txt (.txt).' & @CR & 'And no folder was chosen to tidy.') GUISetState(@SW_SHOW, $s_HWND) ElseIf (Not $v_GUICtrlReadExt <> '' And Not StringInStr($v_GUICtrlReadExt, '.')) And $h_FilePath <> '' Then GUISetState(@SW_HIDE, $s_HWND) MsgBox(64, 'Error', 'You did not enter the correct syntax, you need to enter like "."txt (.txt).') GUISetState(@SW_SHOW, $s_HWND) Else GUISetState(@SW_HIDE, $s_HWND) MsgBox(64, 'Error', 'You did not choose a folder to tidy.') GUISetState(@SW_SHOW, $s_HWND) EndIf SetError(0) Return 0 EndFuncEdit: Just changed a variable in error setting.Edit2: Added a log file to the folder for tracking what was tidied... What date/What time.Edit3:There was an Error that was fixed, I'm actually using this myself... Thanks for the thread ... It's fairly useful. Edited March 17, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
seandisanti Posted March 17, 2006 Share Posted March 17, 2006 Here, I was getting carried away, for what you said you were doing, I think this is how I would have attempted to start it personally:expandcollapse popup#include <file.au3> Local $Label[10], $Combo[10], $Button[10], $FolderToTidy = '' Local $ComboExt = 'All Extensions|.exe|.txt|.rtf|.doc|.bat|.dat|.ico|.ini|.bmp|.jpg|.jpeg|.gif|.png|.tif|.tiff|.dib|.psd|.p dd' $MainGUI = GUICreate('Tidy Folders', 400, 120) $Label[1] = GUICtrlCreateLabel('This will give you the option to tidy up your folders into a specific category.', 20, 10) $Label[2] = GUICtrlCreateLabel('Please choose the extension you would like to tidy', 20, 30) $Combo[1] = GUICtrlCreateCombo('', 260, 27, 100, 100) $Label[3] = GUICtrlCreateLabel('Please choose a folder you would like to tidy', 20, 55) $Button[1] = GUICtrlCreateButton(Chr(133), 240, 52, 30, 20) $Button[2] = GUICtrlCreateButton('Tidy Now', 160, 85, 80, 30) GUICtrlSetFont($Button[1], 14, 4, '', 'Arial Bold') GUICtrlSetData($Combo[1], $ComboExt) GUISetState() While 1 $MainGUI_Msg = GUIGetMsg() Select Case $MainGUI_Msg = - 3;$GUI_EVENT_CLOSE Exit Case $MainGUI_Msg = $Button[1] $FolderToTidy = FileSelectFolder('Select a folder to tidy', '') Case $MainGUI_Msg = $Button[2] $CheckGUIInfo = _CheckGUIInfo($MainGUI, $FolderToTidy, GUICtrlRead($Combo[1])) If $CheckGUIInfo == 1 Then MsgBox(64, 'Complete', 'Your ' & $FolderToTidy & ' has been tidied.') ElseIf $CheckGUIInfo == 2 Then MsgBox(64, 'Error', 'There was an error gathering information') EndIf EndSelect WEnd Func _TidyFolders($h_FilePath, $s_Mask = '*') Local $v_NULL = '', $s_FileName = '', $s_Ext = '', $h_Files = '' Local $a_NameArray, $a_MaskArray = '', $a_FileArray = '' ;Make an array of all the folder/file names $a_FileArray = _FileListToArray($h_FilePath & '\', $s_Mask) ;Create an array of file names and file extensions (keep them even) For $i_FileCount = 1 To UBound($a_FileArray) - 1 $s_PathSplit = _PathSplit($a_FileArray[$i_FileCount], $v_NULL, $v_NULL, $s_FileName, $s_Ext) If $s_PathSplit[3] <> '' And $s_PathSplit[4] <> '' And Not StringInStr($s_PathSplit[3] & $s_PathSplit[4], 'TidyFolderLog.txt') Then $a_NameArray = $a_NameArray & $s_PathSplit[3] & Chr(01) $a_MaskArray = $a_MaskArray & $s_PathSplit[4] & Chr(01) EndIf Next $a_MaskArray = StringSplit(StringTrimRight($a_MaskArray, 1), Chr(01)) $a_NameArray = StringSplit(StringTrimRight($a_NameArray, 1), Chr(01)) ;Create a log file for this folder if one doesn't exist If Not FileExists($h_FilePath & '\TidyFolderLog.txt') Then _FileCreate($h_FilePath & '\TidyFolderLog.txt') EndIf ;Create a log entry in the TidyFolderLog FileWriteLine($h_FilePath & '\TidyFolderLog.txt', _ @CRLF & 'Folder was tidied on: [' & @MON & '/' & @MDAY & '/' & @YEAR & '] at: [' & @HOUR & ':' & @MIN & ':' & @SEC & ']' & @CRLF & '---Files Tidied Were---' & @CRLF) ;Move files to the Destination folder 'Ext+_Files' For $i_ExtCount = 1 To UBound($a_MaskArray) - 1 If $a_MaskArray[$i_ExtCount] <> '' Then FileMove($h_FilePath & '\' & $a_NameArray[$i_ExtCount] & $a_MaskArray[$i_ExtCount], _ $h_FilePath & '\' & StringUpper(StringTrimLeft($a_MaskArray[$i_ExtCount], 1)) & '_Files' _ & '\' & $a_NameArray[$i_ExtCount] & $a_MaskArray[$i_ExtCount], 9) FileWriteLine($h_FilePath & '\TidyFolderLog.txt', $a_NameArray[$i_ExtCount] & $a_MaskArray[$i_ExtCount] & @CRLF) EndIf Next Return 1 EndFunc Func _CheckGUIInfo($s_HWND, $h_FilePath = '', $v_GUICtrlReadExt = '') If $h_FilePath <> '' And ($v_GUICtrlReadExt <> '' Or Not $v_GUICtrlReadExt = 'All Extensions') _ And StringInStr($v_GUICtrlReadExt, '.') Then GUISetState(@SW_HIDE, $s_HWND) If _TidyFolders($h_FilePath, '*' & $v_GUICtrlReadExt) == 1 Then GUISetState(@SW_SHOW, $s_HWND) SetError(1) Return 1 Else GUISetState(@SW_SHOW, $s_HWND) SetError(2) Return 2 EndIf ElseIf $h_FilePath <> '' And (Not $v_GUICtrlReadExt <> '' Or $v_GUICtrlReadExt = 'All Extensions') Then GUISetState(@SW_HIDE, $s_HWND) If _TidyFolders($h_FilePath) == 1 Then GUISetState(@SW_SHOW, $s_HWND) SetError(1) Return 1 Else GUISetState(@SW_SHOW, $s_HWND) SetError(2) Return 2 EndIf ElseIf (Not $v_GUICtrlReadExt <> '' And Not StringInStr($v_GUICtrlReadExt, '.')) And Not $h_FilePath <> '' Then GUISetState(@SW_HIDE, $s_HWND) MsgBox(64, 'Error', 'You did not enter the correct syntax, you need to enter like "."txt (.txt).' & @CR & 'And no folder was chosen to tidy.') GUISetState(@SW_SHOW, $s_HWND) ElseIf (Not $v_GUICtrlReadExt <> '' And Not StringInStr($v_GUICtrlReadExt, '.')) And $h_FilePath <> '' Then GUISetState(@SW_HIDE, $s_HWND) MsgBox(64, 'Error', 'You did not enter the correct syntax, you need to enter like "."txt (.txt).') GUISetState(@SW_SHOW, $s_HWND) Else GUISetState(@SW_HIDE, $s_HWND) MsgBox(64, 'Error', 'You did not choose a folder to tidy.') GUISetState(@SW_SHOW, $s_HWND) EndIf SetError(0) Return 0 EndFuncEdit: Just changed a variable in error setting. Edit2: Added a log file to the folder for tracking what was tidied... What date/What time. Edit3: There was an Error that was fixed, I'm actually using this myself... Thanks for the thread ... It's fairly useful.i would actually go about it a different way. (go figure, i always do stuff the hard way) i was thinking, rather than trying to think of every file type you may have etc, use the registry to figure out what type of file each is, and move to a folder based on that. anybody care to see some code for it? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 17, 2006 Moderators Share Posted March 17, 2006 i would actually go about it a different way. (go figure, i always do stuff the hard way) i was thinking, rather than trying to think of every file type you may have etc, use the registry to figure out what type of file each is, and move to a folder based on that. anybody care to see some code for it?Hmmm... You really don't have to go to ALL that trouble, I mean with _PathSplit() there is no need for registry playing. and with 1000's of extensions out there, you don't have to worry you have the right one . Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
seandisanti Posted March 17, 2006 Share Posted March 17, 2006 Hmmm... You really don't have to go to ALL that trouble, I mean with _PathSplit() there is no need for registry playing. and with 1000's of extensions out there, you don't have to worry you have the right one .path split will give you the extension, but not the common file type name... ie: .au3 = AutoIT3 Script which could be determined from the registry. i wouldn't completely query the registry for each file, i'd create a 2 dimensional array of each extension and the assumed type for each, then just filefindfirstfile...filefindnextfile for each file in the selected folder... so then you're checking against the array... want to see some code? 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