import shutil
t0 = "/home/liviu/A"
t1 = "/home/liviu/B"
t2 = "/home/liviu/C"
s0 = "/home/liviu/Desktop/a"
s1 = "/home/liviu/Desktop/b"
s2 = "/home/liviu/Desktop/c"
target = [t0,t1,t2]
source = [s0,s1,s2]
x = 0
for item in target:
shutil.copy(source[x],target[x])
x += 1
print("done!")
import shutil
target = ["/home/liviu/A","/home/liviu/B","/home/liviu/C"]
source = ["/home/liviu/Desktop/a","/home/liviu/Desktop/b","/home/liviu/Desktop/c"]
x = 0
for item in target:
shutil.copy(source[x],target[x])
x += 1
print("done!")
$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
}
Function Move-ItemToDirectory
{
param
(
[Parameter(Mandatory=$true)][string]$SourceDirectory,
[Parameter(Mandatory=$true)][string]$DestinationDirectory,
[string]$Filter="*.xlsx"
)
$CopyFromPath = $SourceDirectory
$CopyToRootDirectory = $DestinationDirectory
$FileTypeFilter = $Filter
$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
}
}
Unfortunately you must type the full path to files and folders every time you use it.Does either of these two methods have some sort of UI that allows me to choose the folder path each time before I run it? Because the folder path will be different every time.
Add-Type -AssemblyName System.Windows.Forms
$SourceLocation = New-Object System.Windows.Forms.FolderBrowserDialog
$SourceLocation.Description = "Select a Source Directory"
$SourceLocation.ShowDialog()
$DestinationLocation = New-Object System.Windows.Forms.FolderBrowserDialog
$DestinationLocation.Description = "Select a Destination Directory"
$DestinationLocation.ShowDialog()
$CopyFromPath = $SourceLocation.SelectedPath
$CopyToRootDirectory = $DestinationLocation.SelectedPath
$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
}
$File.FullName
$CopyToDirectory
Move-Item $File.FullName -Destination $CopyToDirectory -Force
}
Nope, it doesn't give you the possibility to choose file/folder.I would expect a prompt to show up to let me choose the folder/file paths?
So all I need to do is to replace "Select a Source Directory" and "Select a Destination Directory" with "Z:\Files" and "Z:\Folders" respectively, then run the .py file?Nope, it doesn't give you the possibility to choose file/folder.
You must type in the full path to the file/folder and you can use copy/paste to make it easier.