?
Solved

script to parse and move million files to sub directories

Posted on 2008-10-06
4
Medium Priority
?
206 Views
Last Modified: 2012-05-05
we have a folder, off a single root folder that has approx 1 million files, we want a script or utility that can in groups of say 500, starting from beginning to end based on any sort order, move the files to subdirectories, say the sub directories will be named 00001, 00002 and so on

does anyone have any ideas
0
Comment
Question by:ryanrupert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22657015
0
 
LVL 2

Accepted Solution

by:
simeonf earned 750 total points
ID: 22658437
Hi Ryan,

Give this a try, depending how unique the start of the filenames are.. I used it for sorting many many game roms in to folders based on the name so they could be more easily located. This script moves files to a subfolder based on the first 2 characters of the filename (you could split into more folders by basing it on 3 or more characters).

Otherwise use similar logic with a counter increment for each file in the folder, and when you hit a threshold create a new folder, move new files to there and reset the incremeneter.

Let me know if you want a hand coding this up. And of course give it a good test before running on production data!

Cheers,
Simeon


on error resume next
 
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
Dim strFromFolder
strSourceFolder = "C:\FileSource"
 
Dim strToFolder
strToFolder = "C:\FileDestination"
 
Dim objFolder
Set objFolder = objFSO.GetFolder(strCurrentFolder)
 
Dim objFile
 
For Each objFile In objFolder.Files
	'check if the folder exists, if not create it
	if not objFSO.FolderExists(strToFolder + "\" + left(objfile.name, 2)) then
		objFSO.CreateFolder(strToFolder + "\" + left(objfile.name, 2))
	end if
	newPath =  strToFolder & left(objfile.name, 2) & "\" & objFile.name
	objFSO.MoveFile objFile.Path, newPath
Next
 
'cleanup
set objFSO = nothing
set objFolder = nothing
set objFile = nothing

Open in new window

0
 

Author Comment

by:ryanrupert
ID: 22660036
thanks for the responses, in the interest of full disclosure, I do not have the skills to edit vbscript in any degree
0
 
LVL 38

Assisted Solution

by:Shift-3
Shift-3 earned 750 total points
ID: 22660514
This is also possible in batch.

Paste the script below into a text file with a .cmd extension.  Customize the value of the folder variable with the location of the folder containing the files.  Running the script will move the files into numbered subfolders.

Please test this carefully before using it in a production environment.


@echo off
setlocal enabledelayedexpansion
 
set folder=c:\files
 
set filecount=0
set foldercount=1
set maxfiles=500
 
for /F "tokens=*" %%G in ('dir "%folder%" /A:-D /B') do (
 set /A filecount+=1
 set target=0000!foldercount!
 set target=!target:~-5!
 if not exist "%folder%\!target!" md "%folder%\!target!"
 move "%folder%\%%G" "%folder%\!target!"
 
 if [!filecount!]==[%maxfiles%] (
  set /A foldercount+=1
  set filecount=0
 )
)

Open in new window

0

Featured Post

ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question