0

I need some help getting my head around this.

300-1C6SHFHT5MN654321-08030010.txt
300-1C6SHFHT5MN654321-08030015.txt
300-1C6SHFHT5MN654321-08030025.txt
300-1C6SHFHT5MN654321-08030035.txt
300-1C6HJTFM4ML223344-07040010.txt
300-1C6HJTFM4ML223344-07040020.txt
300-1C6HJTFM4ML223344-07040030.txt
300-1C6HJTFM4ML223344-07040040.txt
300-2C4RC1DG2LR111332-05010025.txt
300-2C4RC1DG2LR111332-05010020.txt
300-2C4RC1DG2LR111332-05010010.txt
300-2C4RC1DG2LR111332-05010005.txt
300-1C6RT7LT6MS544775-01010105.txt
300-1C6RT7LT6MS544775-01010110.txt
300-1C6RT7LT6MS544775-01010115.txt
300-1C6RT7LT6MS544775-01010120.txt

Imagine all the above .txt files in a folder all jumbled up There could be thousands of files in this folder.

I'm trying to figure out the best way to sort and move the files per VIN I was thinking that I could loop through the folder, group all the similar VINs, then take the lowest number

Thinking about looking at at each file, looking at left(22), then looking at the group, and moving the (min/lowest) file number (last8) ...then moving to the next VIN grouping

So, perhaps having a batch file look at the four "300-1C6SHFHT5MN654321-" files and then moving the "08030010.txt" over to a processing folder The .bat will be scheduled to run every five minutes

In the above example, these four files would be moved on the first run:
300-1C6SHFHT5MN654321-08030010.txt
300-1C6HJTFM4ML223344-07040010.txt
300-2C4RC1DG2LR111332-05010005.txt
300-1C6RT7LT6MS544775-01010105.txt

In five minutes, the 2nd run would move these:
300-1C6SHFHT5MN654321-08030015.txt
300-1C6HJTFM4ML223344-07040020.txt
300-2C4RC1DG2LR111332-05010010.txt
300-1C6RT7LT6MS544775-01010110.txt

Any help is appreciated. Thanks!
First time poster. I love this site...has helped me a bunch over the years

Note: I cannot use file date/timestamps. I need the minimum file creation number per VIN

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 1
    Welcome to SO, @henrynlouisville. Glad to hear you are enjoying SO. SO is not a free, bespoke script writing service. I do not see an MRE (Minimal Reproduceable Example) in the question. Please review the information about asking questions at https://stackoverflow.com/help – lit Mar 10 '21 at 20:52
  • ...and when you're done reviewing the "how to ask" stuff, search for similar questions like this one and try to make something work, or at least break in a more creative fashion https://stackoverflow.com/questions/138497/iterate-all-files-in-a-directory-using-a-for-loop – Duodenalsalmons Mar 12 '21 at 13:01

1 Answers1

0

I think I got it...

@echo off
setlocal EnableExtensions enableDelayedExpansion

set "StageFLD=C:\Users\NEWMANALFREDE\Documents\BatchScripts\300dump"
set "ProcessFLD=C:\Users\NEWMANALFREDE\Documents\BatchScripts\300process"
set "theFileName=nothing"

for /R %StageFLD% %%A in (*.txt) do (
    for /F "eol=| tokens=2* delims=-" %%B in ("%%~nA") do (
    set "VIN=%%B"
    set "UpdateTime=%%C"
    setlocal EnableDelayedExpansion
    if "!VIN:~-1!" == " " set "VIN=!VIN:~0,-1!"
    if defined UpdateTime if "!UpdateTime:~0,1!" == " " set "UpdateTime=!UpdateTime:~1!"
    echo VIN=!VIN!
    if defined UpdateTime (echo UpdateTime=!UpdateTime!) else echo %%~na has no UpdateTime.
    if "!VIN!"=="!theFileName!" (echo "same as last") else MOVE /Y %%A %ProcessFLD%\%%~nxA
    endlocal
    )
set "theFileName=!VIN!"
)
endlocal