0

I am not a programmer but I do like some coding and try some automation on a project i have on my mind.

I have a folder (folder1) which contains many pictures. The pictures in this folder are auto-downloaded from the internet so I will not be able to know the specific name of the .jpg files in the folder.

What I want to do is create a batch that will move 1 file (.jpg image)from folder1 to another folder (folder2). Everything that I have found tells me that I must put the name of the file i want to move on the batch. But my problem is I will not know the specific name of the file to be moved. I want just to move 1 (any 1) .jpg file to folder2. so what i think maybe can help is to make the batch to move a random or the first .jpg from folder1 to fodler2.

But i don't know how to script the batch so as to move the 1st file (.jpg file) from fodler1 or a random file from folder1 (whichever option is easier to be scripted) to folder2

What I have tried so far but it doesnt work since it moves all the files from folder1 to folder2 is this:

move 1 /y "C:\Users\xyzuser\Desktop\folder1\*.jpg" "C:\Users\xyzuser\Desktop\folder2"
pause

Anyone can help me to what the correct batch should be so as to move one file (any one, not caring for the name) from folder1 to folder2?

Thanks for any answers in advance!

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
chester
  • 3
  • 2
  • Possible duplicate of [Need to create a batch file to select one random file from a folder and copy to another folder](http://stackoverflow.com/questions/18945521/need-to-create-a-batch-file-to-select-one-random-file-from-a-folder-and-copy-to) – JosefZ Nov 15 '15 at 19:36

1 Answers1

0

this gets the first filename of a Folder (alphabetically):

for %%i in ("C:\Users\xyzuser\Desktop\folder1\*.jpg") do set "file=%%i" & goto :continue
:continue    
echo filename is: %file%
move "%file%"  "C:\Users\xyzuser\Desktop\folder2"

The for would return each matching filename, but goto breaks it after the first file

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • thanks for the reply stephan. i copied and pasted the grey box in your answer in a wordpad and saved it as .bat i run it but i can't see any chnage. i have 5 pictures in folder1 run the batch but no files (with alphabitaclly order) moved to folder2 is it anything i should add or change to the code you sent? i thought i should have used it as you typed it. should i chnage anything? it would be DEEPLY appreciated if you could write here the exact text i should put in the batch? it would be GOLD! :) – chester Nov 15 '15 at 19:23
  • did you remember to change `C:\Users\xyzuser\...`? I doubt, your username is `xyzuser` – Stephan Nov 15 '15 at 21:14
  • well... to be honest at first i forgot to change the xyzuser. :) oops! but still now that i changed i can't see anything changes. i can't see one picture being moved to folder2 after i changed the code,saved as .bat and run again the batch. what the batch now has written is: `for %%i in ("C:\Users\chesterbr\Desktop\folder1*.jpg") do set "file=%%i" & goto :eof echo filename is: %file% move "%file%" "C:\Users\chesterbr\Desktop\folder2"` But i still can't see anything. Should i change anything in the code? I appreciate trying to help :) – chester Nov 15 '15 at 23:18
  • you forgot a "\" in `folder1*.jpg`. It should be `folder1\*.jpg` – Stephan Nov 16 '15 at 06:40
  • added the "\" at folder1.what the wordpad file actually looks like is: http://imgur.com/DXXq2mE after the correction and running the new batch file, no image (alphabetically or any order) was moved to folder2. any last chance correction or ideas/changes i can do? thanks! – chester Nov 16 '15 at 21:14
  • arghh - I'm sorry, logical brain failure. Test my edited code, please. – Stephan Nov 17 '15 at 06:51
  • YES! THANK YOU!! It finally worked! i had problem with it over a week! on forums, yahoo answers and here! finally! :) I guess using the same code style just changing the folder paths i can make the same thing in also different fodlers in the pc right? Again! Much obligged! thanks! – chester Nov 17 '15 at 12:19
  • yes, of course - given, that you have access rights to the source and destination folders. Consider to accept the answer to mark the question solved. – Stephan Nov 17 '15 at 12:35