Computing.Net > Forums > Disk Operating System > script to move files into a hierarch folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

script to move files into a hierarch folder

Reply to Message Icon

Name: hemanthande
Date: July 14, 2009 at 15:06:57 Pacific
OS: Windows Vista
Subcategory: General
Comment:

I need a script to handle moving files into a hierarchical folders structure based on the first 3 letters of the file name.

For example, the file hemanth.txt
would be moved to C:\Archive\h\e\m\hemanth.txt



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: July 16, 2009 at 20:40:29 Pacific
Reply:

i assume you are running vista. so here's a vbscript


Set objFS = CreateObject("Scripting.FileSystemObject")
strArchive = "c:\tmp\"
strFolder = "c:\test"

Set objFolder  = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
	strFilename = strFile.Name
	If Len(strFileName) >=3 Then 
		strone = Mid(strFileName,1,1)
		strtwo = Mid(strFileName,2,1)
		strthree = Mid(strFileName,3,1)
		If Not objFS.FolderExists(strArchive&strone) then
			Set f = objFS.CreateFolder(strArchive&strone)
		End If 
		If Not objFS.FolderExists(strArchive&strone&"\"&strtwo) Then
			Set f = objFS.CreateFolder(strArchive&strone&"\"&strtwo)
		End If 
		If Not objFS.FolderExists(strArchive&strone&"\"&strtwo&"\"&strthree) Then
			Set f = objFS.CreateFolder(strArchive&strone&"\"&strtwo&"\"&strthree)
		End If 			
		Set f = Nothing 
	End If 
Next

GNU win32 packages | Gawk


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: script to move files into a hierarch folder

DOS batch file to move files up www.computing.net/answers/dos/dos-batch-file-to-move-files-up/14778.html

Add commands to text file, how? www.computing.net/answers/dos/add-commands-to-text-file-how/14102.html

Parsing filenames to variables www.computing.net/answers/dos/parsing-filenames-to-variables/14188.html