- Not using pwsh. Using windows powershell.
- Both scripts are in the same folder.
- Both arguments are passed in the exact same way.
- Both arguments are exactly the same, it is a path with a filename.
Command to launch:
powershell -file "E:\Storage\PROGRAMAS\PORTABLES\SimpleContextMenus.0.0.2\Extensions\CLIPS\[TODO]\A\amateur.ps1"
Argument (for both tests):
"E:\Perfil\Desktop\test1\[saroslfs.simpek] - 2020.09.06 - gannekl Redd - Strong binder (1654)-11 -seg002.mkv"
To test:
- Create a dummy file:
[saroslfs.simpek] - 2020.09.06 - gannekl Redd - Strong binder (1654)-11 -seg002.mkv"
- Create both PS scripts from here.
- Launch each and see if it works for you.
WORKS:
#DEBUG!!!
#Start-Transcript -path 'E:\Perfil\Desktop\logfile.txt'
# CHOICE TEMPLATE - CREAR CARPETA
function Show-Menu
{
Write-Host "SI: Presiona 'S' para crearla."
Write-Host "NO: Presiona 'N' para salir."
}
# MOVE Y COMPRUEBA
$MYFILE=$args
$DEST="E:\Perfil\Desktop\testvid"
# EXISTE LA CARPETA DESTINO?
if (Test-Path -LiteralPath $DEST) {
ForEach-Object -process {
Move-Item -LiteralPath $MYFILE -destination $DEST
}
}
# ERROR HANDLER
else {
Write-Host "ERROR EN PATH DE DESTINO: $DEST no existe. Queres crearla?"
do
{
Show-Menu
$input = Read-Host "Elegi"
switch ($input)
{
's' {
MKDIR $DEST
cls
'Hecho, volve a correr el script para mover el archivo'
timeout 2
exit
} 'n' {
exit
}
}
pause
}
until ($input -eq 'n')
}
DOESN’T WORK:
#DEBUG!!!
#Start-Transcript -path 'E:\Perfil\Desktop\logfile.txt'
# CHOICE TEMPLATE - CREAR CARPETA
function Show-Menu
{
Write-Host "SI: Presiona 'S' para crearla."
Write-Host "NO: Presiona 'N' para salir."
}
# VARIABLES
$MYFILE=$args
$DESTVID="E:\Perfil\Desktop\testvid2"
$DESTPIC="E:\Perfil\Desktop\testpic2"
$TYPE='.jpg', '.jpeg', '.png', '.webp', '.bmp', 'tiff'
$EXTN=[IO.Path]::GetExtension($MYFILE)
# PROCESA IMAGENES
if ($EXTN -in $TYPE) {
if (Test-Path -LiteralPath $DESTPIC) {
ForEach-Object -process {
foreach ($ITEM in $MYFILE) {
$FILENAMEEXT=split-path -path $ITEM -leaf
$FILENAME=(Get-ChildItem -path $ITEM).BaseName
$FILEDIR=split-path -path $ITEM
if (Test-Path -literalpath $DESTPIC\$FILENAMEEXT) {
$RAND=Get-Random
$NEWNAME=($FILENAME + '_' + $RAND + $EXTN)
Rename-Item -Path $ITEM -NewName $NEWNAME
Move-Item -Path $FILEDIR\$NEWNAME -destination $DESTPIC
}
else {Move-Item -Path $ITEM -destination $DESTPIC}
}
}
}
# PREGUNTA SI CREAR CARPETA PICS
else {
Write-Host "ERROR EN PATH DE DESTINO: $DESTPIC no existe. Queres crearla?"
do {
Show-Menu
$USERINPUT = Read-Host "Elegi"
switch ($USERINPUT) {
's' {MKDIR $DESTPIC
Clear-Host
'Hecho, volve a correr el script para mover el archivo'
timeout 2
exit
}
'n' {
exit
}
}
pause
}
until ($USERINPUT -eq 'n')
}
}
# PROCESA VIDEOS
else {
if (Test-Path -LiteralPath $DESTVID) {
foreach ($ITEM in $MYFILE) {
$FILENAMEEXT=split-path -path $ITEM -leaf
$FILENAME=(Get-ChildItem -path $ITEM).BaseName
$FILEDIR=split-path -path $ITEM
if (Test-Path -literalpath $DESTVID\$FILENAMEEXT) {
$RAND=Get-Random
$NEWNAME=($FILENAME + '_' + $RAND + $EXTN)
Rename-Item -Path $ITEM -NewName $NEWNAME
Move-Item -Path $FILEDIR\$NEWNAME -destination $DESTVID
}
else {Move-Item -Path $ITEM -destination $DESTVID}
}
}
# PREGUNTA SI CREAR CARPETA VIDS
else {
Write-Host "ERROR EN PATH DE DESTINO: $DESTVID no existe. Queres crearla?"
do {
Show-Menu
$USERINPUT = Read-Host "Elegi"
switch ($USERINPUT) {
's' {MKDIR $DESTVID
Clear-Host
'Hecho, volve a correr el script para mover el archivo'
timeout 2
exit
}
'n' {
exit
}
}
pause
}
until ($USERINPUT -eq 'n')
}
}