+ Reply to Thread
Results 1 to 10 of 10

Moving files from folder based on the excel data

  1. #1
    Registered User
    Join Date
    09-30-2008
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Moving files from folder based on the excel data

    Hello,

    I need help in coding this task please.

    I have a column in a excel file with the image of products, like this:

    COLUMN D
    0600-01BK_D.jpg
    0600-06BK_D.jpg
    0600-77BK_D.jpg
    0770-10TC_D.jpg
    0770-15BK_D.jpg
    0770-77BK_D.jpg
    0800-10BK_D.jpg
    1000-27BK_D-1.jpg
    1015-03SL_D.jpg

    I also have a folder of images where are located the images of the products listed in the excel file. Some products have more than one image, for example, the first product on the excel file have the following 3 images:

    0600-01BK_D.jpg
    0600-01WH_D-1.jpg
    0600-01PK_D-2.jpg

    Other products may only have 1 image, and the folder also contains images not indicated on the xls file.

    I need to move to another folder all the images for each product listed on the excel file, based on the criteria of first characters. I need this criteria be variable; some listing is based on the first 4 characters, others on the first 5 characters, the example explained here use 7 characters. Finally, the files were not found, I need highlight in the excel file.

    Could anyone help me on this please?

    Thanks in advance!!!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving files from folder based on the excel data

    The wildcard thing isn't understood. Your example above seems to clearly indicate the full name of all 3 images for the first product. Detecting and moving images is pretty simple. Can you explain more precisely how the variable length 4-7 characters is supposed to operate?

    Can you provide the actual workbook, the current image folder, the destination image folder, and examples of files listed in the Excel sheet that aren't in the folder?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-30-2008
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Moving files from folder based on the excel data

    Hello JBeaucaire,

    I have enclosed a sample of excel file, a list of files on image folder and examples of how the images are named.

    The criteria has to be variable because I have several group of images. In the example I posted, the first 7 characters are the same for all images, however, I have group of images where only the first 4 characters are the same, other group has the first 5 characters the same, etc, etc.

    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving files from folder based on the excel data

    product image on excel file for item 0011-12:
    no exist
    images for folder:
    0011-12GY_D-1.jpg
    0011-12GY_D-2.jpg
    Because the product is not in the excel file, images for this product will no go to the new folder
    This doesn't follow for me. In the sample excel file this item 0011-12 [U]is listed, so I would expect all the images to be looked for in the folder and moved. Can you clarify?

    As for flexibility in the code length, it looks like you may have solved this by the values you have entered into column A, that seems to hold the actual code to be used each time.

    In my mind the logic is simply:

    1) Go down the ItemNumber column
    2) For each value that column, search the IMAGE folder for images starting with that string and move them

  5. #5
    Registered User
    Join Date
    09-30-2008
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Moving files from folder based on the excel data

    You are right, I'm sorry for that. The product 0011-12 exist on the excel file so the images for this item should be moved. It should read this way:
    product image on excel file for item 0011-12:
    0011-12GY_D-3.jpg
    images for folder:
    0011-12GY_D-1.jpg
    0011-12GY_D-2.jpg
    Because the product is in the excel file, all images for this product will go to the new folder
    Your suggestion is good about using the item number, I can use this column, however, it must be with minimum of 4 characters because I have other listing with only 4 characters identical.

    Thanks!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving files from folder based on the excel data

    It would use WHATEVER is in column A, and WHATEVER that happens to be, it will move every file in your default image folder that starts with those characters.

    You should think this through. If you had images in that folder:

    0011-12GY_D-1.jpg
    0011-12GY_D-2.jpg
    0012-13DF_D1.jpg
    011-FF_D-2.jpg



    If you were searching for a code in column A that was 0011-12, it would find and move the first two files.
    But if you were searching for a code in column A that was 0011, that would find the first two files AND the last file, a total of 3. See how the "shorter" search string could lead to false matches?

    Look at your file names, any chance that could happen?

  7. #7
    Registered User
    Join Date
    09-30-2008
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Moving files from folder based on the excel data

    Hi JBeaucaire,

    I looked at the file names and no, there is no chance that could happen. With a minimum of 4 characters the move will be safe, even with a minimum of 3, most groups of images are ok.

    Thanks!

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving files from folder based on the excel data

    I'd think something like this:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-30-2008
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Moving files from folder based on the excel data

    JBeaucaire,

    I appreciate your help. I tested the code on 5 groups of images with different number of characters and it worked 100%. No one single false match found.

    Thank you!!!

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Moving files from folder based on the excel data

    If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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