AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stuck on moving folder contents based on string contents

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Predated



Joined: 06 Nov 2007
Posts: 42

PostPosted: Tue Dec 18, 2007 6:43 pm    Post subject: Stuck on moving folder contents based on string contents Reply with quote

I have several folders that all hold text and html files. Each of these folders relate to 1 person, but each person can have up to 2 folders that will be vastly different in folder name. I need to consolidate all the text and html files into 1 folder.

I'm having difficulty conceptualizing how I would do this.

Folder names would be similar to the following:

"John" could have files in john2@work and/or conference@work-John2 - 12
"Kandi" could have files in kandi@work and/or conference@work-Kandi - 43
"Amy" could have files in amy2227@work and/or conference@work-amy2227

I'm stumbling on how I would be able to logically tie these folders together, then move the contents. In my head it seems like I could search for the string 'john2' in both folder names, but from there I'm not being able to put the rest of the concept together. I don't have any code written because I'm stuck at the concept phase.

Basically this is more an opinion, I don't want anyone to write it for me, but a push in the right direction from some fresh eyes would be great.
Back to top
View user's profile Send private message
Murp|e



Joined: 12 Jan 2007
Posts: 261
Location: Norway

PostPosted: Tue Dec 18, 2007 6:58 pm    Post subject: Reply with quote

Clarifying exactly what you want to do and possibly writing it down before you write any code is well worth the effort!

First you will need a list that contains all of the names of the people you want to move. The list could look like this:
John
Kandi
Amy

The first thing you do is create a loop which loops through all of the people in this list, something like Loop, parse, PeopleList, `n.

Inside that loop you create another loop which loops through all of the subfolders of a certain folder Loop, %topfolder%\*, 2, 1

For each run through the loop you check if the current folder name (contained in the default variable A_LoopFileName of the inner loop) contains the name of the current person (contained in the defaulft variable A_Loopfield of the outer loop). If it does contain that name, then move all the contents (and possibly delete the folder?).
Back to top
View user's profile Send private message Visit poster's website
Predated-not logged in
Guest





PostPosted: Tue Dec 18, 2007 9:58 pm    Post subject: Reply with quote

True, but this (in my mind) makes it hard to grow the script in the future. I was trying to stay away from a static list.

I think I came up with a way to do it while I was in the car earlier though, I'll post back later.
Back to top
Murp|e



Joined: 12 Jan 2007
Posts: 261
Location: Norway

PostPosted: Tue Dec 18, 2007 10:12 pm    Post subject: Reply with quote

I tried to outline the most straightforward solution. I completely agree that you should avoid static lists, but the described method can be used regardless of how you create the lists.
Back to top
View user's profile Send private message Visit poster's website
Predated



Joined: 06 Nov 2007
Posts: 42

PostPosted: Tue Jan 22, 2008 5:25 pm    Post subject: Reply with quote

Got a chance to come back to this, thanks Murple Smile

Code:

blist = %A_AppData%\.purple\blist.xml
accnt = %A_AppData%\.purple\accounts.xml
xpath_load(b, blist) ;load blist.xml
xpath_load(a, accnt) ;load account.xml
buddy := xpath(b, "/purple/blist/group/contact/buddy/alias/text()")
account := RegExReplace(xpath(a, "/account/account/name/text()"), "/\w+$", "")
protocol := RegExReplace(xpath(a, "/account/account/protocol/text()"), "^prpl-", "")
srcDir = %A_AppData%\.purple\logs\jabber\%account%

;Create new log folder tree based on buddy list names, then set a destination
;directory variable
StringSplit bArray, buddy, `,
Loop %bArray0%
{
    this_buddy := bArray%A_Index%
    FileCreateDir logs\%protocol%\%account%\%this_buddy%
}

;Copy log files to the newly created destination folders
Loop parse, buddy, `,
{
    Loop %srcDir%\*,1,1
    {
        If InStr(A_LoopFileName, A_LoopField)
        {
            Loop %A_LoopFileFullPath%\*,1,1
            destDir = logs\%protocol%\%account%\%A_LoopField%
            FileCopy %A_LoopFileFullPath%, %destDir%
        }
    }
}
Back to top
View user's profile Send private message
Murp|e



Joined: 12 Jan 2007
Posts: 261
Location: Norway

PostPosted: Wed Jan 23, 2008 9:19 am    Post subject: Reply with quote

Looks good to me!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group