Solved Move every first file to a different subfolder (Windows)

January 2, 2019 at 04:43:58
Specs: Windows 10
Dear computing.net,

Is there a way in Windows to move the first file to subfolder 1. The second file to subfolder 2 etcetera. To make it more clear I will explain the setup.

Setup:

Source folder: Here I have all the files in 1 folder (2000 files)

The first file needs to come in subfolder 1.
The second file needs to come in subfolder 2.
The third file needs to come in subfolder 3.
Etcetera

Cutting/Moving is enough, if file1 is moved to subfolder1 then file1 doesn't have to exist anymore in the source folder. But if copying is easier for the script then moving/cutting then thats not a problem.

Target: Subfolders: 1 2 3 4 5 6 7 8 9 etc.

Preference is: cmd batch scripting but if it is only possible with vbscripting or powershell then that's not a prolbem.

Thanks in advance.

Best Regards,

Tim


See More: Move every first file to a different subfolder (Windows)

Reply ↓  Report •

✔ Best Answer
January 4, 2019 at 07:05:34
It's a simple round robin approach. Make a list of directories, and rotate around that list as you go through the files.

dir -File | %
Get all of the files (directories excluded). For each file . . .

-Begin { $i = 0; $dirs = dir -Directory }
But first! Set our counter to 0, and make a list of directories.

{ mv $_ $dirs[$i++ % $dirs.Length] }
. . . move it to the next entry on the directory list

Unless you're asking about the encodedcommand part. It's just the powershell line wrapped up in base64. Used to get around any command line parsing issues.

How To Ask Questions The Smart Way

message edited by Razor2.3



#1
January 2, 2019 at 09:58:11
i'll post my attempt in batch in aprox. 15hours :D

i5-6600K[delid]@4.7GHz/@1.392v LLC=6 | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | MSI Armor RX 570 4GB@1415Mhz core@1.2v/1920MHz


Reply ↓  Report •

#2
January 2, 2019 at 10:11:46
Thank you very much! :D

Reply ↓  Report •

#3
January 2, 2019 at 10:20:12
Many ways to do this in PowerShell; this is the first to mind:
dir -File | % -Begin { $i = 0; $dirs = dir -Directory } { mv $_ $dirs[$i++ % $dirs.Length] }

Oh, and here's the batch version:

powershell -encodedcommand bABzACAALQBGAGkAbABlAHwAJQAgAC0AYgAgAHsAJABpAD0AMAA7ACQAZAA9AGwAcwAgAC0AYQBkAH0AIAB7AG0AdgAgACQAXwAgACQAZABbACQAaQArACsAJQAkAGQALgBMAGUAbgBnAHQAaABdAH0A

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

Related Solutions

#4
January 4, 2019 at 06:18:48
@Razor2.3 thanks for you answer, this one is a little bit hard for me to understand that commando.

@hidde663 do you know a way? did you try something


Reply ↓  Report •

#5
January 4, 2019 at 07:05:34
✔ Best Answer
It's a simple round robin approach. Make a list of directories, and rotate around that list as you go through the files.

dir -File | %
Get all of the files (directories excluded). For each file . . .

-Begin { $i = 0; $dirs = dir -Directory }
But first! Set our counter to 0, and make a list of directories.

{ mv $_ $dirs[$i++ % $dirs.Length] }
. . . move it to the next entry on the directory list

Unless you're asking about the encodedcommand part. It's just the powershell line wrapped up in base64. Used to get around any command line parsing issues.

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •

#6
January 7, 2019 at 06:07:28
RE #4 ended up not having enough time after all.

I could try today, but i would first like to know if #5 worked or not.

i5-6600K[delid]@4.7GHz/@1.392v LLC=6 | 2x4GB Crucial-DDR4-2400CL17@14-15-15-28 1T 3000MHz@1.4v | MSI Armor RX 570 4GB@1410Mhz core@1.2v/1920MHz


Reply ↓  Report •

#7
January 11, 2019 at 08:33:21
Thanks Razor!
@Hidde you also thanks for your reactions

Reply ↓  Report •

Ask Question