Welcome Guest.   Make a donation to an author on the site November 23, 2014, 09:58:59 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Check out and download the GOE 2007 Freeware Challenge productivity tools.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: Moving selected files to date based folders  (Read 9418 times)
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« on: April 08, 2008, 04:11:55 PM »

It would be neat to have an explorer right click funtion that can move files in a folder to date based(monthly, yearly or user defined intervals) folders. So you select the files run the app, select the interval, the software checks modified or creation dates of files, creates date absed folders and move files in proper folders.

Logged
Armando
Charter Member
***
Posts: 2,683



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #1 on: April 08, 2008, 08:52:15 PM »

I'm curious : there are probably many uses for such a utility, but why will you (personally) want to move files to date "based" (identified?) folders? For archiving purpose I guess?
Logged

"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #2 on: April 08, 2008, 09:07:30 PM »

Yes archiving mainly. Sometimes I endup with many files within one folder. Best way would be cataloging based on dates I assume.

Logged
Armando
Charter Member
***
Posts: 2,683



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #3 on: April 08, 2008, 10:47:08 PM »

I see. Yes, this is how I do it too -- but for backup or archiving on external media only. Otherwise I don't bother. A good  naming scheme and desktop search software are my friends as far as my internal hard drive is concerned.  smiley
Logged

"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #4 on: April 10, 2008, 10:08:58 PM »

Here's an extension that Lifehacker covered recently
http://lifehacker.com/378...r-utils-right+click-tools

Haven't tested this myself...yet.

I may already have a standard vbs drop script that you could put in the sendto folder.

Is the directory structure something like this:
Year|Month|Day
Eg. 2008|04|10
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #5 on: April 10, 2008, 10:25:00 PM »

I installed it and it does not do anything under xp, and it looks like it does not work on selected files


edit: It did not like non standard installation location. Installing under program files worked.

Sir Smiley, I use Day_Month_Year generally. Althou Year_Month_Day would be more applicable to directories I guess

« Last Edit: April 10, 2008, 10:42:31 PM by kartal » Logged
Armando
Charter Member
***
Posts: 2,683



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #6 on: April 10, 2008, 11:17:29 PM »

Year_Month_Day seems like the way to go for any classification, whether folders or files. Stuff get all mixed up otherwise -- years don't repeat, but days and month do, so it makes more sense.  smiley
Logged

"I suppose it can be said that I'm an absent-minded driver. It's true that I've driven through a number of red lights on occasion, but on the other hand, I've stopped at a lot of green ones but never gotten credit for it."
Glenn Gould
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #7 on: April 10, 2008, 11:44:15 PM »

I normally use light year but human years is fine in this case too smiley
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #8 on: April 11, 2008, 02:12:17 PM »

Next you'll want star date! Wink

Are you meaning moving into just one folder or a directory tree?
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #9 on: April 11, 2008, 10:04:13 PM »

Here's a simple vbscript file with no recursion.

[copy or print]
'*********************************************************
' Sorter.vbs
'
' 3:30 PM 11/04/2008
'
' A. Timperley aka SirSmiley
'
' Purpose:
' Sort Files Into Date Specific Folders. Creates folders if none exist.
' Non-Recursive. Eg. Doesn't do subfolders
' Inputs:
' Dropped Folders
' Returns:
' Msgbox notification on completion
'*********************************************************
'Year|Month|Day
Dim objArgs : Set objArgs = WScript.Arguments
Dim arrDropFldrs()
Dim arrDropFiles()

Dim blnRecurse : blnRecurse=False

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set the path to your target folder here
Dim objTargetFldr : objTargetFldr = "C:\Programming\Sandbox\x"
' Special character
' Use double quotes with no space if you wish to have a straight date
Dim sSC : sSC = "."
' Configure Sorting Method
' 1 = Date Created | 2 = Date Last Accessed | 3 = Date Last Modified
Dim iSortDate : iSortDate = 3

'Splits dropped folders into an array
' You can drop multiple folders this way
For I = 0 to objArgs.Count - 1
If I <0 Then
WScript.Quit
  Else
' Build Array from Dropped Items
ReDim Preserve arrDropFldrs(I)
arrDropFldrs(I)=objArgs(I)
  End If
  Call FilesToFolder
Next

' Checks to see if Target Date Folder Exists
' Creates one if none exists
Function DateFolder(strDate)
' Format Date
strSortDate = DatePart("yyyy",strDate)&sSC
If DatePart("m",strDate) < 10 Then
strSortDate = strSortDate & "0"
End If
strSortDate = strSortDate & DatePart("m",strDate)&sSC
If DatePart("d",strDate) < 10 Then
strSortDate = strSortDate & "0"
End If
strSortDate = strSortDate & DatePart("d",strDate)
strTargetFldr = objTargetFldr&"\"&strSortDate
If objFSO.FolderExists(strTargetFldr) Then
DateFolder=strTargetFldr&"\"
Else'If objFSO.FolderExists(strTargetFldr)=False Then
objFSO.CreateFolder(strTargetFldr)
DateFolder=strTargetFldr&"\"
End IF
End Function

' Creates File Collection from Folders in Array. Sorts Accordingly
Sub FilesToFolder
For i=0 To UBound(arrDropFldrs)
strFolder=arrDropFldrs(i)
' Get Folder
Set objFolder = objFSO.GetFolder(strFolder)
' Get's File Collection
Set objFileCol=objFolder.Files
For Each File In objFileCol
If iSortDate = 1 Then
strTargetFldr = DateFolder(File.DateCreated)
objFSO.MoveFile File,strTargetFldr
ElseIf iSortDate = 2 Then
strTargetFldr= DateFolder(File.DateLastAccessed)
objFSO.MoveFile File,strTargetFldr
ElseIf iSortDate = 3 Then
strTargetFldr= DateFolder(File.DateLastModified)
objFSO.MoveFile File,strTargetFldr
End If
Next
Next
msgbox "Complete"
End Sub
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #10 on: April 11, 2008, 10:20:23 PM »

Thanks SirSmiley, but how do you use it?
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #11 on: April 11, 2008, 10:32:30 PM »

I can add in some basic input boxes if you want or you can do it this way:

Edit it with Metapad or Notepad++ (or MS Notepad if you must Wink.
Paste and save as a vbscript file. The parts you need to change are:
  • objTargetFldr="Path you want to create the date folders in"
  • Sorting Method- Set for Date Last Modified by default see the comment for changes
  • Change sSC = "." to what ever character you want to divide the date by or "" for no character
  • Rearrange the If Statements in the DateFolder Function to change how you want to display the folders

Then move the edited file to your SendTo Folder. When you right click on a folder(s) and select the file it will move the folders. You can also drag and drop the folders you want to sort directly on to the script



objTargetFolder="Path to folder
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #12 on: April 11, 2008, 11:45:12 PM »

SirSMiley, I was hoping that I would not need to define a target folder. Because generally speaking if I select some files and drop them into dated folders, probably I would want new date folders to be in the current folder. Moving them to somewhere else afterwards is easier job because.


I will try this method now thou.
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #13 on: April 12, 2008, 11:04:06 AM »

Ooo! That's actually fairly easy compared to what I've been working on.

Delete or comment out everything after declaring the Target folder variable:
[copy or print]
Dim objTargetFldr ': objTargetFldr = "C:\Programming\Sandbox\x"

In the FilesToFolder Sub Add One Line:
[copy or print]

' Find the line below
Set objFolder = objFSO.GetFolder(strFolder)
' Add the next line right after it
objTargetFldr = objFolder
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #14 on: April 12, 2008, 12:40:20 PM »

Works!! Thanks

It would be great if it works on selected files as well. A the moment it works only on selected folders
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #15 on: April 12, 2008, 02:13:13 PM »

also would it be possible to have it only with year and month? We can then add it as seperate script to send to
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #16 on: April 12, 2008, 08:44:49 PM »

When you say sort files do you mean together with the folders as in you drop/send 5 folders and 20 files?
Also are the files all going to be from one folder? If that's the case then it's pretty simple but, if it's files for many folders through Explorer Search then it would slow down the script quite a bit since you'd have to get the parent folder for each file then create the sub folders.

To change the format to year and month do the following in the date folder function:
[copy or print]
' Comment or delete the special character function at the end of the next line
strSortDate = strSortDate & DatePart("m",strDate)'&sSC
' Comment out or delete the next if statement and string
' If DatePart("d",strDate) < 10 Then
' strSortDate = strSortDate & "0"
' End If
' strSortDate = strSortDate & DatePart("d",strDate)
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #17 on: April 12, 2008, 09:41:18 PM »

all selections would be in same folder
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #18 on: April 13, 2008, 04:06:45 PM »

Here you go. You'll have to modify the date function still.
[copy or print]
'*********************************************************
' Sorter.vbs
'
' 3:30 PM 11/04/2008
'
' A. Timperley aka SirSmiley
'
' Purpose:
' Sort Files Into Date Specific Folders. Creates folders if none exist.
' Non-Recursive. Eg. Doesn't do subfolders
' Inputs:
' Dropped Folders
' Returns:
' Msgbox notification on completion
'*********************************************************

Dim objArgs : Set objArgs = WScript.Arguments
' Declore array's
Dim arrDropItems() ' all dropped items

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set the path to your target folder here
Dim objTargetFldr ': objTargetFldr = "C:\Programming\Sandbox\x"
' Special character
' Use double quotes with no space if you wish to have a straight date
Dim sSC : sSC = "."
' Configure Sorting Method
' 1 = Date Created | 2 = Date Last Accessed | 3 = Date Last Modified
Dim iSortDate : iSortDate = 3

'Splits dropped folders into an array
' You can drop multiple folders this way
For I = 0 to objArgs.Count - 1
If I <0 Then
WScript.Quit
  Else
' Build Array from Dropped Items
ReDim Preserve arrDropItems(I)
arrDropItems(I)=objArgs(I)
  End If 
Next

Call ArraySort
' Sort Array
Function ArraySort
For i=0 To UBound(arrDropItems)
' Determines if dropped item is a folder or file
  If objFSO.FolderExists(objArgs(i)) Then
Call SortFolders(objArgs(I))
ElseIf objFSO.FileExists(objArgs(i)) Then
Call SortFiles(objArgs(I))
End If 
Next
End Function
' Checks to see if Target Date Folder Exists
' Creates one if none exists
Function DateFolder(strDate)
' Format Date
strSortDate = DatePart("yyyy",strDate)&sSC
If DatePart("m",strDate) < 10 Then
strSortDate = strSortDate & "0"
End If
strSortDate = strSortDate & DatePart("m",strDate)&sSC
If DatePart("d",strDate) < 10 Then
strSortDate = strSortDate & "0"
End If
strSortDate = strSortDate & DatePart("d",strDate)
strTargetFldr = objTargetFldr&"\"&strSortDate
If objFSO.FolderExists(strTargetFldr) Then
DateFolder=strTargetFldr&"\"
Else'If objFSO.FolderExists(strTargetFldr)=False Then
objFSO.CreateFolder(strTargetFldr)
DateFolder=strTargetFldr&"\"
End IF
End Function

' Creates File Collection from Folders in Array. Sorts Accordingly
Sub SortFolders(strFolder)
Set objFolder = objFSO.GetFolder(strFolder)
objTargetFldr = objFolder'
' Get's File Collection
Set objFileCol=objFolder.Files
For Each File In objFileCol
If iSortDate = 1 Then
strTargetFldr = DateFolder(File.DateCreated)
objFSO.MoveFile File,strTargetFldr
ElseIf iSortDate = 2 Then
strTargetFldr= DateFolder(File.DateLastAccessed)
objFSO.MoveFile File,strTargetFldr
ElseIf iSortDate = 3 Then
strTargetFldr= DateFolder(File.DateLastModified)
objFSO.MoveFile File,strTargetFldr
End If
Next
msgbox "Folder Contents Sorting Complete"
End Sub

' Sort's Files to Date Formated Folders
Sub SortFiles(strFile)
Set strFile=objFSO.GetFile(strFile)
strFolder=objFSO.GetParentFolderName(strFile)
strFolder=objFSO.GetAbsolutePathName(strFolder)
Set objFolder = objFSO.GetFolder(strFolder)
objTargetFldr = objFolder
If iSortDate = 1 Then
strTargetFldr = DateFolder(strFile.DateCreated)
objFSO.MoveFile strFile,strTargetFldr
ElseIf iSortDate = 2 Then
strTargetFldr= DateFolder(strFile.DateLastAccessed)
objFSO.MoveFile strFile,strTargetFldr
ElseIf iSortDate = 3 Then
strTargetFldr= DateFolder(strFile.DateLastModified)
objFSO.MoveFile strFile,strTargetFldr
End If
msgbox "Files Sorting Complete"
End Sub
Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #19 on: April 13, 2008, 04:17:20 PM »

One thing to remember is there are limits to how many files that can be passed using WScript Arguments.
I think it's 25?

Then if you've got hundreds of files you want to select and run this script on, I think there may be other issues. Wink
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #20 on: April 13, 2008, 04:37:15 PM »

Thanks!

Here is the issue with selected files, it brings up a confirmation pop up dialog for every file. But it works.

Logged
SirSmiley
Member
**
Posts: 64


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #21 on: April 13, 2008, 07:49:17 PM »

Simple Solution. Comment out the msgbox
Logged
kartal
Supporting Member
**
Posts: 1,529


View Profile Give some DonationCredits to this forum member
« Reply #22 on: April 13, 2008, 07:57:37 PM »

Thanks!! I will try now
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.041s | Server load: 0.15 ]