create folders based on extensions files & moved files

Ali M

Active Member
Joined
Oct 10, 2021
Messages
330
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
hi experts

I want macro create folder's name is FILES-2022 based on current year in this directory "C:\Users\PC-ALM\Desktop\files" which contains variety files of differnt extensions .
so folder FILES-2022 should create many folders based on files extensions are existed in this directory "C:\Users\PC-ALM\Desktop\files" for instance FILE_PDF, FILE_DOCX ......

and should create the months folders inside folders extensions (FILE_PDF, FILE_DOCX ......)like JAN,FEB and moves the files extensions from "C:\Users\PC-ALM\Desktop\files"to are relating with folder extensions into folder month based on the month .
thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Are you using the revised line in post #7 ?

Look at the output in the Immediate window created by this line to see if it explains what's happening.
VBA Code:
        Debug.Print "MOVE " & FSfile.Path, destSubfolder
Add this line to output the creation date of each file:
VBA Code:
        Debug.Print FSfile.DateCreated
 
Upvote 0
Are you using the revised line in post #7 ?
yes and I posted what I got in post#10
this what I see in the Immediate window

MOVE C:\Users\PC WORLD\Desktop\dd\columns.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
MOVE C:\Users\PC WORLD\Desktop\dd\Copy of Listbox-1.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
MOVE C:\Users\PC WORLD\Desktop\dd\CORR .xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
 
Upvote 0
where I put this line
VBA Code:
        Debug.Print FSfile.DateCreated
 
Upvote 0
Immediately above the existing Debug.Print line so I can see the creation date of the file being moved.
 
Upvote 0
this is what I got
4/28/2022 11:15:45 PM
MOVE C:\Users\PC WORLD\Desktop\dd\16.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:45 PM
MOVE C:\Users\PC WORLD\Desktop\dd\1q.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:46 PM
MOVE C:\Users\PC WORLD\Desktop\dd\22.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\alphasort_listbox.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:46 PM
MOVE C:\Users\PC WORLD\Desktop\dd\Bridgestone Sales Report 11 Nov 2021.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:51:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\cases (2).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:51:11 PM
MOVE C:\Users\PC WORLD\Desktop\dd\CL (1).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\COLOR1 .xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\COLOR2.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\columns.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\Copy of Listbox-1.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:09:24 PM
MOVE C:\Users\PC WORLD\Desktop\dd\CORR (abdo meghari).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\CORR.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:09:24 PM
MOVE C:\Users\PC WORLD\Desktop\dd\Creating Tables from data1.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:06 PM
MOVE C:\Users\PC WORLD\Desktop\dd\delsp.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\EX (2) (1).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\EX (MKLAQ).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:51:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\EX.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\fill repeatedly.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\im.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:47 PM
MOVE C:\Users\PC WORLD\Desktop\dd\invoice.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\invoice1.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\ITEM.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\JOHN.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\LINK TOO.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\Listbox.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\MF.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\MK.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:51:09 PM
MOVE C:\Users\PC WORLD\Desktop\dd\MLLAQ.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:48 PM
MOVE C:\Users\PC WORLD\Desktop\dd\multi.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:49 PM
MOVE C:\Users\PC WORLD\Desktop\dd\new.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:49 PM
MOVE C:\Users\PC WORLD\Desktop\dd\OUTPUT.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:09:26 PM
MOVE C:\Users\PC WORLD\Desktop\dd\Power Query to Append and Merge Tables (abdo meghari).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\RESULT (2).xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/26/2022 1:48:07 PM
MOVE C:\Users\PC WORLD\Desktop\dd\RESULT.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:09:26 PM
MOVE C:\Users\PC WORLD\Desktop\dd\Sample_maras.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:49 PM
MOVE C:\Users\PC WORLD\Desktop\dd\SEARCH.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:49 PM
MOVE C:\Users\PC WORLD\Desktop\dd\SEARCH1.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:49 PM
MOVE C:\Users\PC WORLD\Desktop\dd\sumif .xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
4/28/2022 11:15:49 PM
MOVE C:\Users\PC WORLD\Desktop\dd\vv1.xlsm C:\Users\PC WORLD\Desktop\dd\FILES-2022\FILE_XLSM\APR\
 
Upvote 0
All the creation months are April then, so the code is correctly moving them to the APR folder.
 
Upvote 0
as I said in post#10 I no know if you see it . the orginal created date some files are in JAN,FEB then should create folders JAN,FEB and move the files into it , but surprisingly after move to APRIL folder the created date some files in JAN,FEB convert to 4/28/2022
that's why I said the code works based on current month

this case is strange !!
 
Last edited:
Upvote 0
Add this line immediately above the End Sub:
VBA Code:
    Shell "cmd /k DIR /A-D /TC " & Chr(34) & sourceFolder & Chr(34)
It opens a command window and lists the creation dates of files in the sourceFolder, so you can compare them with the creation dates in the Immediate window.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top