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 

Folder Manipulation

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



Joined: 15 May 2007
Posts: 39

PostPosted: Wed Jun 04, 2008 2:51 pm    Post subject: Folder Manipulation Reply with quote

So I am having a bit of trouble implementing a script I would like to make.

What I want to do is take a list of folders (with files and more folders in them) and rename them with the modified date at the beginning of the folder name. So for example taking a folder and renaming it from "FolderName" to "20080604 - FolderName".

Any help on how to do this or how to loop through a list of folders?
Back to top
View user's profile Send private message
Dra_Gon



Joined: 25 May 2007
Posts: 313

PostPosted: Wed Jun 04, 2008 3:17 pm    Post subject: Reply with quote

"FileMoveDir" should do what you want as far as renaming files. Also, look up the Date and Time variables {A_Now might be a good one}.
Maybe something like:
Code:

FileSelectFolder, myFolder   ; User selects TOP folder

IfNotEqual myFolder,
   Loop, FilePattern , 2, 0  ; ,2 = for ONLY folders - ,0 = NO subfolders  "Loop (files & folders)"
     FileMoveDir, %myFolder%\*, %A_Now%, R  ;R = Rename only



<<NOT TESTED>>

This SHOULD work on a group of folders below the one selected. The A_Now is typically in YYYYMMDDHH24MISS format {with seconds so folders would have that difference in names} though that can be changed using "FormatTime" and creating your own Time format within the script.
Hope this is helpful {others may know of better ways too}.

Ciao,
Dra'Gon
_________________

For a good laugh {hopefully} >> megamatts.50megs.com

My WritersCafe profile>>
http://www.writerscafe.org/writers/BlueDragonFire/
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Wed Jun 04, 2008 3:36 pm    Post subject: Reply with quote

Code:
#SingleInstance, Force
SetWorkingDir %A_ScriptDir% 
SetBatchLines -1

; Build a list of folders - ** Deepest Folder on Top-Of-List **
Loop, *.*,2,1 
  folders = %A_LoopFileLongPath%`n%folders%

StringTrimRight, Folders, Folders, 1
 
Loop, Parse, folders, `n, `r 
  {
    SplitPath, A_LoopField, SubFolder, Folder
    FileGetTime, fStamp, %A_LoopField%, M
    NewFolderName := Folder "\" SubStr(fStamp,1,8) " - " SubFolder
    FileMoveDir, %A_LoopField%, %NewFolderName%, 1
  } 


Smile


Last edited by SKAN on Wed Jun 04, 2008 3:41 pm; edited 1 time in total
Back to top
View user's profile Send private message
icefreez



Joined: 15 May 2007
Posts: 39

PostPosted: Wed Jun 04, 2008 3:40 pm    Post subject: Reply with quote

I managed to get a script to do everything I want except get the Modified date for the folder.

My script currently does this. Asks for user name, finds root folder, then asks for folder with in that root folder (for fast renaming in a specific folder) then renames it to (date) - FolderName (Username)

Code:
SetBatchLines, -1                                                   ; Make the operation run at maximum speed.

InputBox, uname, Enter your name                                       ;get name
if uname =
    exitapp

FileSelectFolder, mainsourcedir,,,Select Root Folder                        ;select root folder
if WhichFolder =
    exitapp

loop
{
FileSelectFolder, WhichFolder, %mainsourcedir%,,Select a folder to rename.         ;select folder to rename
SplitPath, WhichFolder, FName, FDir                                       ;split directory path for usage
;msgbox, About to rename %WhichFolder% to %FDir%\%A_YYYY%%A_MM%%A_DD% - %FName%      ;tell what it will be renamed to
if WhichFolder =
    exitapp
else
    FileMoveDir, %WhichFolder%, %FDir%\%A_YYYY%%A_MM%%A_DD% - %FName% (%uname%), R   ;rename it
}

esc::
exitapp
return
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Wed Jun 04, 2008 3:42 pm    Post subject: Reply with quote

Did you read my post/code ?
Back to top
View user's profile Send private message
icefreez



Joined: 15 May 2007
Posts: 39

PostPosted: Wed Jun 04, 2008 3:46 pm    Post subject: Reply with quote

Oh no, I must have been typing when you posted it Razz

Thx
Back to top
View user's profile Send private message
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