Solved

batch script file to move based on

Posted on 2010-11-19
10
816 Views
Last Modified: 2012-05-10
I need a batch script to move the last file in a folder called "data" but we need to check the last modified time stamp using WMIC we need to go down to miliseconds
WMIC DATAFILE WHERE "PATH='\\Log\\'" GET Name, LastModified, name

Open in new window

0
Comment
Question by:CalmSoul
  • 6
  • 4
10 Comments
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34175965
I think should do what you want.  If it seems to get the correct file then change the ECHO at the end to a MOVE of the file to wherever you want it.

@echo off
for /F "tokens=1*" %%A in ('wmic datafile where "path='\\Log\\'" get LastModified^,Name ^| find /i /v "LastModified" ^| sort') do set LatestFile=%%B
echo %LatestFile%

Open in new window

~bp
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 34176336
where you have mentioned to move to data folder?
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 34176430
how we can move files in batches eg first 100 then next 100 so on...
need to add a FOR loop
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 34176449
You'll need to be clearer about what you need the script to do please.  I thought you just wanted to find the most recent file, and move it.  But it sounds like you want to move them all, into some groupings by date/time.  Not clear yet though.

~bp
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 34176482
bp:

Basically we have 30,000 files we need to move to different folder oldest first (based on date/time miliseconds) then next oldest and then so on.

I am sorry if we were not clear earlier?
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 34176863
bp: any update we need as soon as possible
0
 
LVL 5

Author Comment

by:CalmSoul
ID: 34185356
bp:

any update?
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34185357
@echo off
setlocal EnableDelayedExpansion
set Count=0
set Group=1
for /F "tokens=*" %%A in ('dir /a-d /b /o-d /tc "c:\source\*.*"') do (
  set /A Count+=1
  if !Count! GTR 20000 (
    set /A Group+=1
    set Count=1
  )
  echo Group:!Group!, Count:!Count!, File:%%A
  move "%%A" "c:\destination\"
)

Open in new window

0
 
LVL 5

Author Comment

by:CalmSoul
ID: 34188609
I  am getting following
C:\Log\New Folder>setlocal EnableDelayedExpansion

C:\Log\New Folder>set Count=0

C:\Log\New Folder>set Group=1

C:\Log\New Folder>for /F "tokens=*" %A in ('dir /a-d /b /o-d /tc "c:\log\*.*"')
do (
set /A Count+=1
 if !Count! GTR 20000 (
set /A Group+=1
 set Count=1
)
 echo Group:!Group!, Count:!Count!, File:%A
 move "%A" "C:\Log\New Folder\New Folder\"
)

C:\Log\New Folder>(
set /A Count+=1
 if !Count! GTR 20000 (
set /A Group+=1
 set Count=1
)
 echo Group:!Group!, Count:!Count!, File:move.bat
 move "move.bat" "C:\Log\New Folder\New Folder\"
)
Group:1, Count:1, File:move.bat
The system cannot find the file specified.

C:\Log\New Folder>(
set /A Count+=1
 if !Count! GTR 20000 (
set /A Group+=1
 set Count=1
)
 echo Group:!Group!, Count:!Count!, File:Log_13-8-2010.txt
 move "Log_13-8-2010.txt" "C:\Log\New Folder\New Folder\"
)
Group:1, Count:2, File:Log_13-8-2010.txt
The system cannot find the file specified.

C:\Log\New Folder>pause
Press any key to continue . . .

Open in new window

0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34193471
It looks like you saved the BAT script as a file called MOVE.BAT.  That will be a problem, since the MOVE command is a reserved internal command name.  Rename the BAT from from MOVE.BAT to something else like MYMOVE.BAT.

~bp
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Date variable in batch file 2 44
How can i open a .fxp file 3 38
Windows Updates Batch Files (now with executables!) 32 59
Do Wend Macro not working 22 33
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question