I need to move thousands of files from one folder to new folders


  1. Posts : 3
    XP 64 AND WINDOWS 7 32BIT
       #1

    I need to move thousands of files from one folder to new folders


    I need to figure out a way to take thousands of .dwg,.docx,.xlsx, ect. files and organize them all into folders. I want to take file named 54321.xlsx and 54321.docx and put them in the folder 54321. Right now all my .docx files are in a folder, but I want them all seperated by seperate folders. I have already made the 100k folders for each job using a batch file. Now I just need to figure out how to organize the files into the corresponding folders. Please Help!
      My Computer


  2. Posts : 28,845
    Win 8 Release candidate 8400
       #2

    RHODESSURVEYING said:
    I need to figure out a way to take thousands of .dwg,.docx,.xlsx, ect. files and organize them all into folders. I want to take file named 54321.xlsx and 54321.docx and put them in the folder 54321. Right now all my .docx files are in a folder, but I want them all seperated by seperate folders. I have already made the 100k folders for each job using a batch file. Now I just need to figure out how to organize the files into the corresponding folders. Please Help!
    One caveat. That many nested folders will slow the computer to a crawl unless you have really good hardware (RAM (8gigs), CPU,. i7, etc).
      My Computer


  3. Posts : 3
    XP 64 AND WINDOWS 7 32BIT
    Thread Starter
       #3

    file organizing


    Thank you,
    Yes I realized that already. I created subfolders to help. 80,000 files are under a file called archive. We will not need to access this much. 8,000 are in a different sub folder and we only have 2,000 folders in the main file. I just need to figure out how to get our files in the correct folders.
      My Computer


  4. Posts : 2,528
    Windows 7 x64 Ultimate
       #4

    Well this is really a job for a 20-30 line script. Python, perl whatever...

    Don't know what your skill level with that sort of thing is, but even as a coding noob it may take less time to figure out how to write a python script than to do it all by hand. (And pick up an awesome skill for future problems like this at the same time)

    (An experienced scripter could probably do it in 5 minutes if here is anyone like that in the company)
      My Computer


  5. Posts : 3
    XP 64 AND WINDOWS 7 32BIT
    Thread Starter
       #5

    wow thanks


    I appreciate the info. I guess I am going to be trying to learn python script this weekend. Any direction to send me on the net to find how to do this?
      My Computer


  6. Posts : 2,528
    Windows 7 x64 Ultimate
       #6

    Well you can google for "Python Scripting" and install the interpreter (from here http://www.python.org/) and it comes with a simple editor. Then try googling "Getting started with python". I don't have any specific site recomendations. There will be tons of sample code if you can find one that seems close to what you want to do. Like "Sort files using pyton".

    For example, this sample does several of the things you will need to do for your task even though it doesn't do exactly the same thing:

    Using Python to delete old files and keep newest ones : Graham Lyons

    But it shows how to iterate over all files in a foilder, find information about them and then do something with them... ANd it's only 7 lines of code. Yours may be a bit longer but should still be pretty simple.
      My Computer


  7. Posts : 5,092
    Windows 7 32 bit
       #7

    Are you planning to only access these via program or command line? I'm just thinking Explorer or any Gui file manager may choke when sifting through all the file and folder attributes.

    Also wide may be better than deep if you plan on using Explorer. It balks if the length of the nested folder paths start approaching 260 characters.
      My Computer


  8. Posts : 31
    Windows 7 Home Premium 64 OEM
       #8

    You know, if you're a windows nut... and you like scripts... you should be hanging out here:
    Hey, Scripting Guy! How Can I Move Files Based on a Portion of the File Name? - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs
    That one sounds similar, but you can edit or search the site if thats not what you're looking for.
    Make sure it will work on your system first. http://technet.microsoft.com/en-us/s...enter/dd940113
    I've only tried this on XP so I'm not sure what may have changed with 7.
    Last edited by giblets; 28 Oct 2011 at 19:47.
      My Computer


  9. Posts : 5,092
    Windows 7 32 bit
       #9

    I have an AutoIt3 function that returns the "base name" of a path. For example, _FileBaseName("C:\MyFolder\MyFile.txt") returns "MyFile"

    You could use it to put the file into the proper folder

    Whatever programming language you decide to use should either have a canned function that does the same, or have library functions you can use to roll your own without too much difficulty

    Basically it just returns the characters after the last backslash up to but not including the first extension dot

    Code:
    ; return the basename part of a file path
    ; works only for files with extension
    ; e.g. returns "test" for c:\folder\test.exe path
    ;
    Func _FileBaseName($path)
    	If $path = "" Then Return ""
    	If StringLen($path) < 3 Then Return ""
    
    	Local $pos = StringInStr($path, "\", 0, -1)
    	$pos += 1
    	Local $tmp = StringMid($path, $pos)
    	Return StringLeft($tmp, StringInStr($tmp, ".", 0, -1) - 1)
    EndFunc   ;==>_FileBaseName
    So in AutoIt3 you would do something like
    $basename = _FileBaseName($path)

    FileMove($basename & ".*", $basename & "\*.*)

    The "&" is string concatenation operator. So it becomes "move files with base name x inside folder named x"

    Should be pretty simple if the folders are all on the same level.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 08:08.
Find Us