#207891 - 2013-10-08 10:47 PM
looking to better understand the results I'm getting
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
Hello all,
I'm in the process of writing an administrative kix script for setting up and scheduling defragmentation of specific files / folders for our admin team. My intent / goal with it is a script that will provide a prompt for which paths are to be defragmented and then a number of actions take place.
I'm not going to get into all the moving parts I'm planning, but the relatively simple parts of it are something I'm having some problems with.
Here is the code i'm currently struggling with:
? "Enter paths to de-fragmented, separated by commas: "
Gets $PathInput
$PathInput = split($PathInput,",")
;
$Contig="C:\psscripts\contig\contig.exe -s"
$DefragCustomLog="C:\psscripts\contig\defraglog.txt"
;
;
For Each $Path in $PathInput
? $Path
Next
;
For Each $Path in $PathInput
shell "%ComSpec% /c $Contig $Path>>$DefragCustomLog"
Next
The above code will not work when a path with spaces is entered. Specifically, paths like C:\program files, won't work when typed in UNLESS they are put in quotes "C:\program files" or in non-8dot3 format (C:\progra~1).
I can work around that, but would love to know if there's someway I can code around it :).
I also am curious what can be done about the data entry prompt. At the prompt to enter paths, as soon as you reach the end of the dos line . . your characters start over-writing each other and it's really hard to know what's being typed. Is there possibly another way that I can leverage a prompt for users to be entering path data that would be easier for data entry?
thoughts and feedback appreicated,
Lan
|
|
Top
|
|
|
|
#207892 - 2013-10-09 12:24 AM
Re: looking to better understand the results I'm getting
[Re: Tsguy]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
Lan,
Three points - First, you're better to use semicolons to delimit paths, as it's already a common method in the PATH statement. It pays to be consistent.
Second, you'd be better served to build the shell command in $Cmd, then run Shell $Cmd. This way, even for simple commands, you can dissect it and print it before you run it.
Third, use single quotes for Kix strings. DOS likes double quotes, and using single quotes in Kix allows you to easily embed double quotes in your commands that you Shell or Run.
So, try tyis:For Each $Path in $PathInput
$Cmd = '%COMSPEC% /c ' ; note trailing space!
$Cmd = $Cmd + $Contig + ' "' + $Path + '">>DefragCustomLog'
'About to run:' @CRLF $Cmd @CRLF
Shell $Cmd This way, you see the command before you run it - you can verify that the path is properly surrounded with double quotes. When things work as desired, you can comment-out or remove the debug message (or - wrap it in an If $DEBUG command).
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#207897 - 2013-10-09 12:59 AM
Re: looking to better understand the results I'm getting
[Re: Glenn Barnas]
|
Tsguy
Getting the hang of it
Registered: 2010-01-18
Posts: 67
Loc: Oregon
|
As always Glenn, you are a fount of kix knowledge 
I'm trying several kix actions that are new to me on this one, so the advice is appreciated.
Will see what I can work up regarding the suggestions and will repost code in a bit.
Lan
|
|
Top
|
|
|
|
#207915 - 2013-10-15 04:55 AM
Re: looking to better understand the results I'm getting
[Re: Tsguy]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
He is a fountain of KiX knowledge so use him while you can because his fountain of youth if filling up fast
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|