batchfile to create folder (date) and move files according to filename (date)

Hi "Experts" :-),
I have two cameras taking pictures of a construction work every 30 sec 24/7.
The files all ends up in a folder and I need to have them moved to a folder for each day.
The file format is :
image14-07-16_15-29-20-41.jpg
image14-07-16_15-28-50-41.jpg
image14-07-16_15-28-20-41.jpg

Currently I have 90.000 files to sort and it would be a lot easyer to use a batch file script or whatever can solve the task.

I expect the program to create the dir for each day and copy the relevant files to that dir.
The files are on a Win 2008R2 server.

Hope someone has the knowledge to solve the task,

Br

Henrik / Denmark
SoederAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arjun VyavahareTechnical ConsultantCommented:
Hi,

Below command will help you but you need to explore this command more :

forfiles /P "c:\data\PRODDB\dir" /M *.DMP /D +0 /C "cmd /c copy @path d:\test"

I hope this will help you.

Regards,
Arjun
0
oBdACommented:
Try this; it just uses the file's name to determine the target folder name. the variable "FolderSorted" contains the root folder where you want the pictures to end up; the "date" folder will be appended.
The script is currently in test mode and will only display the commands it would normally run; remove the uppercase ECHOs in lines 10 and 11 to run it for real:
@echo off
setlocal enabledelayedexpansion
set FolderIncoming=C:\Temp
set FileMask=image*.jpg
set FolderSorted=C:\Temp
for %%a in ("%FolderIncoming%\%FileMask%") do (
	set FileName=%%~na
	echo Processing '!FileName!' ...
	set TargetFolder=!FileName:~5,8!
	if not exist "%FolderSorted%\!TargetFolder!" ECHO md "%FolderSorted%\!TargetFolder!"
	ECHO move "%%a" "%FolderSorted%\!TargetFolder!"
)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SoederAuthor Commented:
Hi contributors,
thank you for your input.
I have tried both suggestions without any luck.
If you can be more concrete to the task or if anybody else have a better solution please get back to me.
Br

Henrik
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

oBdACommented:
"without any luck" is not really helpful as error description.
What exactly happened when you tried to run my script?
Please create a folder "C:\Temp", and copy 5 of the image files in question into this folder.
Open a new command prompt, "cd" into the folder where you saved my script, and run it without any changes.
What is its output?
Note that you can right-click the command prompt's title bar in order to select the output, you don't have to re-type it.
0
SoederAuthor Commented:
Hi oBdA,
sorry for not giving you a more specific feedback.
I have made a folder on an external disk Q called test.
I then copied some thousand files into it an created a .bat file named sorter.bat with the following content:

setlocal enabledelayedexpansion
set FolderIncoming=Q:\Test
set FileMask=image*.jpg
set FolderSorted=Q:\Test

for %%a in ("%FolderIncoming%\%FileMask%") do (
      set FileName=%%~na
      echo Processing '!FileName!' ...
      set TargetFolder=!FileName:~5,8!
      if not exist "%FolderSorted%\!TargetFolder!" md "%FolderSorted%\!TargetFolder!"
      move "%%a" "%FolderSorted%\!TargetFolder!"

When I run the bat file, it flashes a dos prompt window for a second and nothing have changed.
I runs so fast that I cant see what is happening.
I then tried to put some pause commands into the script to get hold of what happened, but it seems like they are ignored, it still just executes the script with a short flash.
I have tried to place the bat file in and out of the folder to see if that had any influence, but the result were the same.

I would appreciate a lot if you would help me get this up and running.

Br

Henrik
0
oBdACommented:
As I said: Open a command prompt (by entering cmd.exe into the "run" box), enter "cd /d T:\he\Path\to\the\script.cmd", and enter the script name. That way, the command prompt will remain open when the script is done, and even errors will be displayed.
One error I can see in the script you posted is that the closing ")" in the last line is missing. Note the "Select all" button under the code box which makes it easier to copy script to the clipboard without missing anything.
0
SoederAuthor Commented:
Hi oBdA,
The script is WORKING :-)
Thank you for your patience and time to guide me.

I will credit your first answer.

Br
Henrik / Happy Dane
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.