How to move all *.jpg files to another folder (Powershell)
I’m a huge fan of 9gag and over the years I have collected a lot of posts. I wanted to create a personal database of the posts, because they are all experiencies that can be relived.
I haven’t formatted my machine for 3+ months, which is unusual for me. Therefore I had a LOT of *.jpg files sitting in my downloads folder and it slowed me down.Â
I was a linux user for a long time, so I didn’t know how to achieve such things in windows. But after using powershell for a couple of hours, I really liked it. At first it seemed silly, closed source bull-shit. I’ve recently read Hackers & Painters so I was thinking bash is much simpler and efficient. But it turned out that Powershell had a different philosophy. Everything is objects instead of text streams. One can use the entire .net libraries. Awesome.
So how to move all *.jpg files to another folder
mv $(Get-ChildItem . *.jpg) /.newfolder
First you create a folder with mkdir
Then you use the mv to move files. Mv takes two parameters the object to be moved and the destination.
$() evaluates a command just like in bash.Â
Get-ChildItem is the equivalent of ls or dir in powershell.Â
. represents the current directory
*.jpg is the wildcard expression of all jpg files.
I hope it helped you! I glazed at the screen for a while after it worked.
If you want to learn more about powershell Get-Help :D
PS: BTW If update-help doesn’t work, try running it with administrator privileges.Â
Edit: You could also do this by specifying a path parameter directly to move. But where is the fun in that ;-)
mv -Path .\*.jpg -Destination .\newfolder