+ Reply to Thread
Results 1 to 9 of 9

Sorting files into respective folders

  1. #1
    Registered User
    Join Date
    11-01-2017
    Location
    Malaysia
    MS-Off Ver
    2003
    Posts
    7

    Sorting files into respective folders

    Hi all,

    I am writing a code to sort out 40-50 pdf files daily into a few respective folders. (Let's name these folders Alpha, Bravo and Charlie for now)

    Each of these pdf files have a unique file name at the front and a date indicated at the back.

    Some example of it is as follows:
    DAS213D_20061012.pdf (This file needs to be at Alpha folder)
    GFGSTER_20061012.pdf (This file needs to be at Bravo folder)
    SAEAHTA_20061012.pdf (This file needs to be at Charlie folder)

    Any tips from the pros?

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Sorting files into respective folders

    Welcome to the forum!

    I see no logic in your naming convention. Why would the first file go into the first folder? Is that what you want. by file name and folder name sort order? So for 50 files you want to put in 50 folders? Would the folders exist already?

  3. #3
    Registered User
    Join Date
    11-01-2017
    Location
    Malaysia
    MS-Off Ver
    2003
    Posts
    7

    Re: Sorting files into respective folders

    Hi!

    Thanks for replying and apologies for the ambiguity.

    Yes. that is what i need. To move specific files into specific folders. And nope. There will be around 50 files but at the end of the day, they will all need to be placed in the 3 respective folders.

    I have learnt to create the folders using MkDir.

    The files are currently at C:\Users\Jaack\Desktop\Source
    Some example of it is as follows:
    DAS213D_20061012.pdf (This file needs to be at C:\Users\Jaack\Desktop\Destination\Alpha folder)
    GFGSTER_20061012.pdf (This file needs to be at C:\Users\Jaack\Desktop\Destination\Bravo folder)
    SAEAHTA_20061012.pdf (This file needs to be at C:\Users\Jaack\Desktop\Destination\Charlie folder)
    ASFDSFH_20061012.pdf (This file needs to be at C:\Users\Jaack\Desktop\Destination\Alpha folder)
    123GDAS_20061012.pdf (This file needs to be at C:\Users\Jaack\Desktop\Destination\Alpha folder)
    SADFSER_20061012.pdf (This file needs to be at C:\Users\Jaack\Desktop\Destination\Charlie folder)

    There are a total of 50 files similar to those above and needs to be sorted out.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Sorting files into respective folders

    I still don't see a correlation between filenames and folders.

    If you have a naming convention or a list of prefix names that goes to each folder, that can be done. Some make a table for such things.

  5. #5
    Registered User
    Join Date
    11-01-2017
    Location
    Malaysia
    MS-Off Ver
    2003
    Posts
    7

    Re: Sorting files into respective folders

    Hmm.
    On the 1st day, the file is obtained as
    DAS213D_20061012.pdf
    On the next day, the file is obtained as
    DAS213D_20061013.pdf

    The date at the back of the file changes, but the first 7 letters of each file remains the same. Is this the correlation that you are referring to?

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Sorting files into respective folders

    No,
    We want you to create a table that defines every possible start of the file name (or give us a precise rule that separates Alpha/bravo/charlie [and possibly "do nothing"] and never fails).
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Sorting files into respective folders

    No.

    Correlation means this versus that. This is the file name. That is the folder name. http://www.dictionary.com/browse/correlation?s=t

    You have two parts to your file name. What part of the file name correlates or has a relationship to the folder name? Or, does the content in the file govern what folder it goes to? If that is the case, after the pdf creation, that becomes difficult unless you have Adobe Acrobat Pro.

    IF you have a table of base file names in a column and matching folder names in the next column, paste it or attach the file. Click the Go Advanced button in lower right of a reply, and then click the Manage Hyperlinks below the reply box.

    In post #3, you have them going to folders a,b,c,a,a,c. There is no logic that I can see for why you did that. The files are not even sorted in any manner obvious to me.

    I can show you how to get the filenames and order by filename or date, and how to "move" them to another folder but without knowing the logic, I don't see what purpose it would serve. When you say sort, I guess you mean move.

    If you don't care about correlation, it is easy to move the files to any set of folders and then loop the folders again if more files.
    Last edited by Kenneth Hobson; 11-02-2017 at 09:01 PM.

  8. #8
    Registered User
    Join Date
    11-01-2017
    Location
    Malaysia
    MS-Off Ver
    2003
    Posts
    7

    Re: Sorting files into respective folders

    Thanks scottiex and kenneth for trying your best to help me.

    Apologies for using the wrong jargon here and there.

    There is no correlation or relationship between the file and the folder name at all. And thankfully, it is not the content in the file that i am looking for, it is just the file name of the pdf.


    [QUOTE=Kenneth Hobson;4777026
    When you say sort, I guess you mean move.

    If you don't care about correlation, it is easy to move the files to any set of folders and then loop the folders again if more files.[/QUOTE]

    Yup, this is what i need.

    In really layman terms and a little bit of coding knowledge, this is what I have in mind.

    If filename contains "DAS213D" or "ASFDSFH", move it to C:\Users\Jaack\Desktop\Destination\Alpha
    else if filename contains "GFGSTER", move it to C:\Users\Jaack\Desktop\Destination\Bravo

    Loop this until there are no more files left

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Sorting files into respective folders

    Run this in mMain module, Sub rnFiles(). Always backup files before testing macros.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] vba to copy specific files extension to their respective folders
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-28-2017, 07:27 PM
  2. Files to be moved respective folders
    By Jayakumar1313 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2016, 12:33 PM
  3. Replies: 0
    Last Post: 10-15-2014, 04:37 AM
  4. VBA code that cut .pdf files and copy in respective folders
    By waqarqrl in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 10-07-2013, 04:46 AM
  5. macro should pick up the data from the respective Client folders
    By snn3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-10-2013, 03:14 AM
  6. Replies: 2
    Last Post: 10-14-2012, 06:53 AM
  7. Saving mails in respective folders
    By ramserp in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2010, 04:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1