Sorting a file list in WIndows

-1

Got a list of color photos from Hatton1.jpg to Hatton72.jpg each photo has an identical black and white one named Hatton1-2.jpg through Hatton72-2.jpg

Is there a way to strip out the -2 files to a separate directory?

GeoffMarbella

Posted 2018-01-30T12:07:50.873

Reputation: 1

Answers

1

Use the move command with the appropriate arguments:

move *-2.jpg c:\somefolder

Keltari

Posted 2018-01-30T12:07:50.873

Reputation: 57 019

1

This is a bit tricky, because of short file names:-

  • In order to maintain some sort of compatibility with old programs which were able to handle only short file names, Windows provides an alternative 8.3 name for each longer file name.
  • The 8.3 names are in the format *~N.???, where * is the beginning of the file name and N is an integer (where there are few clashes) - see dir /x.
  • Unfortunately, searching for *~2.* will find some of these short names as well as the files you want, with *~2.* in the long name.

In cmd, go to the directory with the files: you can list the ones you want to move with:

dir /b | findstr "~2.jpg"

Ideally, you should be able to use:

for /f %f in ('dir /b | findstr "~2.jpg"') do move "%f" NewDirPath

Unfortunately again, you can't use a pipe in an embedded command in a for loop, so you need to use two commands (or three to remove the temporary file):

dir /b > Files.lst
for /f %f in ('findstr "~2.jpg" Files.txt') do move "%f" NewDirPath
del Files.lst

It's not a very elegant solution, but you're probably only doing it once. If you need to do it repeatedly, put the commands in a batch file and make sure you double the % in the loop variable:

...
for /f %%f in ('findstr "~2.jpg" Files.txt') do move "%%f" NewDirPath
...

AFH

Posted 2018-01-30T12:07:50.873

Reputation: 15 470

And what is wrong on move *-2.jpg ? Why is this complicated solution needed instead? – duDE – 2018-01-30T14:23:12.270

@duDE - I thought I made it clear: move *-2.jpg is liable to move irrelevant files with matching short names. – AFH – 2018-01-30T16:16:31.840

Sorry, AFH, I see it now :) +1 – duDE – 2018-01-31T09:13:47.567

0

Using PowerShell you can use Get-ChildItem together with Move-item.

It would look something like this:

Get-ChildItem -Filter '*-2.jpg' -Recurse | %{Move-Item $_ C:\Target}

I didn't test that code but it should be very similar. Using just the regular Windows search and dragging the files would also likely work.

Seth

Posted 2018-01-30T12:07:50.873

Reputation: 7 657