-2

I face the following issue in Windows. I have thousands of subfolders in a main folder (let's call it data\ ) and I want to move a big subset of them in another folder (let's call it data2\ ). In a .txt file I have a list of the exact names of the folders that I want to move. Is there a way to do that with the cmd?

I make a simple example to make the issue more clear. In the folder data\ I have the subfolders A, B, C, D and E. In a text file I have the list of names:

A C E (one name in each line)

I want to move the subfolders A, C and E to the folder data2.

Thanks a lot :)

  • Which programming language? Please [post your code](http://stackoverflow.com/help/mcve) so that we can see [what you have tried so far](http://whathaveyoutried.com/). – GoBusto Apr 17 '15 at 15:53
  • You are asking to do this with cmd on windows, so I assume you mean DOS. You can check this to read file in dos http://stackoverflow.com/a/4527915/3885927 and then use move command instead of echo that was shown in the link – user3885927 Apr 17 '15 at 16:04
  • Yes, I meant DOS... Sorry if I was not clear enough and thanks for the link you provided me and for your suggestions. I've been searching a lot in google... – Joseph Greenfield Apr 17 '15 at 16:29

1 Answers1

0

I suggest using PowerShell instead of plain cmd. You can take advantage of various Linux command aliases. To move the folder data\A to data2\A it is as easy as mv data\A data2. Now you also need to do this as part of a loop, because you have a text file containing the names of all these folders that you would like to move. I am not on a windows system right now, so I can't test the below code. I adapted a for loop that I saw here

$files = cat list.txt
foreach ($f in $files)
    { mv data\$f data2 }
Kevin Tindall
  • 375
  • 5
  • 16