Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file to move files based on date created  (Read 26200 times)

0 Members and 1 Guest are viewing this topic.

Akia

  • Guest
Batch file to move files based on date created
« on: June 10, 2005, 06:59:30 AM »
Dear users:

I want to create a start.bat file which allows me to move files that I create daily and move them onto folders based on the files date created.  

I do data entry each day and I have to drag and drop my files every evening.  I searched around the net and got to this place and I hope someone could help me.


Example:
File            Date created
a.doc        6-07-05   12:30PM
b.doc        6-08-05   11:23AM
1.doc        6-09-05   8:30AM
2.doc        6-09-05   9:40AM

I would create a folder called "Document 6-07-05" and then move "a.doc" into it.   I created "Document 6-08-05" and move all files on that date to it.  I do this everyday before I go home.   Each day I created about 50-100 documents and I wish there's way for me to move it faster.

Someone wrote me this start.bat but it didn't help much.  I save everything on "Today Documents" folder then at end of day I run this batch file.

@echo off
c:
cd\
md c:\"Documents Date"
cd\"Today Documents"
move *.* c:\Documents Date"
cd\
echo on

This works ok, but I have to rename the "Documents Date" to correct date.  For instance, today I will run the start.bat file then go into "Documents Date" and rename to "Documents 6-09-05"

I hope you could help.

Thank you in advance,
Akia







Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch file to move files based on date created
« Reply #1 on: June 10, 2005, 01:13:00 PM »
This piece of code should work based on what you gave us.

Code: [Select]

for /f "tokens=1-4 delims=/ " %%i in ('date /t') do (
     set mm=%%j
     set dd=%%k
     set yy=%%l
)
set TodayDir="c:\Documents %mm%-%dd%-%yy%"
c:
cd\
md %TodayDir%
cd "\Today Documents"
move *.* %TodayDir%
cd\


It would have been helpful to know your OS as not all batch commands are backward compatable.

Now that the date is available, you could use XCOPY and then delete contents of the the daily directory. Batch does not do arithmetic especially date calculations, so any previously dated files have to be done manually.

Hope this helps. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Akia

  • Guest
Re: Batch file to move files based on date created
« Reply #2 on: June 13, 2005, 06:54:43 AM »
Thank you so much.  It worked like a charm.  I have XP Prof.  This is wonderful as I will run it everyday so there won't be any previous date.

Again thanks for your help.

Regards,
Akia

Greg McDonald

  • Guest
Re: Batch file to move files based on date created
« Reply #3 on: June 13, 2005, 08:47:48 AM »
There're spaces in between the date, how can I make it to read as 6-13-05 and not 06 - 13 -2005

Thanks

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch file to move files based on date created
« Reply #4 on: June 13, 2005, 09:25:26 AM »
Greg McDonald,

Are you the same person as the original poster? If not please do not piggyback on someone else's thread. Start your own post.

Actually the code works according to the specs presented and with no embedded spaces in the date. :P You might have missed the part where I mentioned that batch language is not always backward compatable.

If you need a two digit year, you need to use a SET statement to extract them.

If you don't need a leading zero for the months, use a conditional SET statement for Jan thru September.

8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Akia

  • Guest
Re: Batch file to move files based on date created
« Reply #5 on: June 14, 2005, 09:35:02 AM »
Yes, Greg is my bf.  Same office and thanks for the help.