9
\$\begingroup\$

NB : Everything presented in the situation is totally fake and had just been put here to make the challenge a little more fun ;) ... Or maybe not ;)


=== === BEGINNING TRANSMISSION === ===

Hello,
I recently had a disk failure. I hopefully had backups and I now want my photos back. However, EVERY backup looks corrupted in the parallel universe where I live. But that's not a problem, because we had special tools to help user find their files back. They work a little bit like yours, and looks around a disk for headers that look like images. As they are still in beta, the software recovers any image it finds, gives it a random name and outputs a list containing:

  • The model of the camera that took the photo, or a single - if not available. Note that the model could contain spaces, but no -.

  • A tab char (\t, ASCII 9)

  • The name of the photo file.

The file is a standard text file and looks like that:

[...]
-   uyfeiebsvH.jpg
-   hv754ce758.gif
-   8321214736.jpg
-   FgnvsfHJBs.jpg
-   OMGILOVYOU.jpg
-   HElloDearH.png
-   umanHAYYSG.jpg
COOLCAM S1332   umanIAYYSG.jpg
iCell 7G    1234567890.jpg
[...]

The file is quite big, and I can't rely on my little Ubro to move all the file that have a model in a separate directory.


Dear Human, I need your help. I want you to move all photos that have data about the camera in a separate directory, so I could find my little cute cat pictures out of this mess of icons, screenshots...

However, these backups are taking place on My LiquidStateDrive46X, so I don't have a lot of space left (and I'm actually downloading the Internet, so, you know, it's difficult to download something else while doing that. I just can barely surf the web and you are the only one I've found, human!)

Don't let me live that way ! Please, write my a small program that will do the work for me, and save a little Ubro.


  • As this is code-golf, the shortest program wins

  • I need to be able to launch you program, HUMAN ! So make sure your program has an existing interpreter.

  • You can expect the list file to be in the directory where I launch your script. It will be named ./list.txt

  • You need to move images to ./withmodel/

  • Every image recovered is in the same directory from where I launch your program

  • No image have a - in his name. Same goes for camera models

  • It need to be a real program, not a simple function.

  • No internet access, I'm DOWNLOADING! This is really important.

  • I need my cat images quickly, or I can't survive: This code-golf will end on the 10th of October, if I'm still alive on this day.

=== === END OF TRANSMISSION === ===

\$\endgroup\$
8
  • \$\begingroup\$ You may use any language that have an interpreter by the time the challenge were posted, so it looks like a standard loophole, yes. I don't want to restrict too much on this... \$\endgroup\$
    – WayToDoor
    Oct 5, 2015 at 19:10
  • \$\begingroup\$ Ok, I've edited that line to be a bit more clear, in my opinion. If you don't like it feel free to revert. \$\endgroup\$ Oct 5, 2015 at 19:14
  • 3
    \$\begingroup\$ It's puuuurfect ;)! Thanks you! \$\endgroup\$
    – WayToDoor
    Oct 5, 2015 at 19:15
  • \$\begingroup\$ I've put an answer, but I wonder if I'm missing something. Why might this need internet access? Is it important that the disk doesn't have much space left? Is this significant "I cant rely on my little Ubro to move all the file that have a model in a separate directory."? \$\endgroup\$ Oct 5, 2015 at 19:30
  • \$\begingroup\$ This should'nt need internet. I just put the rule in case... The disk has not much space left => write the shortest program possible. And the Ubro is pure storytelling, it's not significant \$\endgroup\$
    – WayToDoor
    Oct 5, 2015 at 19:34

1 Answer 1

9
\$\begingroup\$

PowerShell (v4), 58 49 bytes

(gc list.txt)-replace"^[^-]*`t"|mv -des withmodel


# Previous 58 byte version
(gc list.txt)-notmatch'^-'-replace".+`t"|mv -des withmodel
  • get-content of the list
  • remove camera models up to the tab by replacing them with nothing. This won't change the lines starting with "-".
  • pipe into the move command, destination folder 'withmodel'. This will hit a lot of errors for the unchanged lines starting with "-", but since none of the files has a "-" in the name, that won't move any incorrect files, only the right files will be moved.
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Holy crap ... I had almost the exact same thing. Finally, a challenge that PowerShell is almost designed for, and I was a slight bit too slow. Have a +1. \$\endgroup\$ Oct 5, 2015 at 19:32
  • 1
    \$\begingroup\$ @TimmyD Indeed; it's not particularly great for golfing, but with the way "-replace" and "|mv" work on multiple things at once, this has got to be one of its strongest areas. \$\endgroup\$ Oct 5, 2015 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.