📎 AI Summary:
The thread discusses automating the process of copying CSV files into folders named after each file, with contributors suggesting solutions using Python and PowerShell scripts. The original poster questions whether the scripts offer a user interface for selecting folder paths dynamically since paths vary each time. Responses include how to incorporate folder selection dialogs into PowerShell scripts and mention that Python scripts require manual path specification unless modified. Overall, the discussion highlights scripting options for automating file organization on Windows, with some emphasis on adding UI prompts for user convenience.

q988988

New Member
Member details
Joined
Nov 21, 2019
Messages
19
Thread Author #1
I have a list of csv files that have to be copy into a list of folders with same names. Rather than manually cutting each one into the corresponding folder, is there a trick of doing this in windows?
An image from 'How to copy files into corresponding folders?'. The images show three Excel files on the left being grouped into three folders named A, B, and C on the right.
An image from 'How to copy files into corresponding folders?'. The images show three Excel files on the left being grouped into three folders named A, B, and C on the right.
 

Last edited by a moderator:
Solution
Yeah a script would be the most efficient especially if you have a large number of files. In powershell it would be like this
Code:
$CopyFromPath = "C:\Some\Path"
$CopyToRootDirectory = "C:\Some\Other\Path"
$FileTypeFilter = "*.xlsx"

$Files = Get-ChildItem -Path $CopyFromPath -Filter $FileTypeFilter

foreach($File in $Files)
{
    $DirectoryName = "\$File.BaseName"
    $CopyToDirectory = "$CopyToRootDirectory$DirectoryName"

    if(-not(Test-Path $CopyToDirectory))
    {
        New-Item -Path $CopyToDirectory -ItemType Directory
    }
    Move-Item $File.FullName -Destination $CopyToDirectory -Forc
}

or it could be created as a function so that you can pass it different values for reuse
Code:
Function Move-ItemToDirectory
{
    param...

q988988

New Member
Member details
Joined
Nov 21, 2019
Messages
19
Thread Author #22
How about the file names? I just did a test... the code worked fine with the file names A,B,C but not for a bit more complex names. And the code also worked fine for the folders with existing non-xlsx files. SO the only issue left would be the file names. Is it possible to make some tweaks on the code so it works for the file name such as 22B_1 or 100_2?
 

q988988

New Member
Member details
Joined
Nov 21, 2019
Messages
19
Thread Author #24
This is weird...because all the files with simple names got moved over except the one shown in the screenshot...
1574914200658.png
 

q988988

New Member
Member details
Joined
Nov 21, 2019
Messages
19
Thread Author #25
Maybe there is a limitation in the code by default that only allows for the file name to have a certain number of character?
 

q988988

New Member
Member details
Joined
Nov 21, 2019
Messages
19
Thread Author #26
I tested a couple of more times...it just did not work the a more complicated file name rather than A,B,C... anyone can help out?
 

Neemobeer

Windows Forum Team
Staff member
Member details
Joined
Jul 4, 2015
Messages
8,995
That's because the filter is set to xlsx only you'd need to add further types to filter on.