Parameters Not Initialized for Empty Folder

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

Post Reply
pj
Gold Member
Gold Member
Posts: 471
Joined: 2006 Jan 26, 14:01
Location: Florida

Parameters Not Initialized for Empty Folder

Post by pj »

I've had to work around this little glitch, but thought I'd bring it up to at least discuss the reasoning or if it can be added to the long list of minor fixes:

Essentially, parameters $P, $C and $U are null if the folder in focus has no files, but $L and $R are set. Easily tested with this simple VBS:

Code: Select all

' x2 cmd line:  > wscript.exe TestArgs.vbs "$P" "$C" "$U" "$L" "$R" 

' ARGUMENT COUNT ALWAYS RETURNS "5"
   MsgBox "Arguments.Count = [ " & WScript.Arguments.Count & " ]", 0

' ARGUMENTS ARE NULL STRINGS IF NO FILES EXIST IN FOLDER
   msg = "Arguments: " & vbCrlf & _
         "$P   = [ " & WScript.Arguments.Item(0) & " ]" & vbCrlf & _
         "$C   = [ " & WScript.Arguments.Item(1) & " ]" & vbCrlf & _
         "$U   = [ " & WScript.Arguments.Item(2) & " ]" & vbCrlf & _
         "$L   = [ " & WScript.Arguments.Item(3) & " ]" & vbCrlf & _
         "$R   = [ " & WScript.Arguments.Item(4) & " ]" & vbCrlf & _
         "End of Arguments"

   MsgBox msg, 0
When the folder "F:\New Folder" is the focused tab but no files or folders exist, the results are:
Arguments:
$P = [ ]
$C = [ ]
$U = [ ]
$L = [ D:\INACTIVE PANE ]
$R = [ F:\New Folder ]

End of Arguments
This is true for folders newly created or folders with all files and folders deleted.
Add a file or folder into the folder and now $P and $C return the expected strings.
Arguments:
$P = [ F:\New Folder ]
$C = [ New Folder ]
$U = [ F:\New Folder\x2scrap.png ]
$L = [ F:\INACTIVE PANE ]
$R = [ F:\New Folder ]
End of Arguments

Is this expected behavior?

------------------------------
PJ in (IT'S FINALLY FALL) FL
(edit: corrected error in the output box for "populated" folder.)
Last edited by pj on 2018 Oct 29, 11:02, edited 1 time in total.
User avatar
nikos
Site Admin
Site Admin
Posts: 15771
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Parameters Not Initialized for Empty Folder

Post by nikos »

this is by design
when does it become a problem for you?
pj
Gold Member
Gold Member
Posts: 471
Joined: 2006 Jan 26, 14:01
Location: Florida

Re: Parameters Not Initialized for Empty Folder

Post by pj »

When setting up a new project folder, I can't get the folder's name for further processing. I have to actually search all items in the hard-coded parent folder (sFolder) to find the newest item, then use that result to continue building the new project folder structure. I can't just use the $P variable from a tab to get the new folder name.

Code: Select all

Sub NewestSubfolderInFolder(sFolder)
    Set MainFolder = fso.GetFolder(sFolder)
    For Each fldr In MainFolder.SubFolders
            If fldr.DateLastModified > LastDate Or IsEmpty(LastDate) Then
            LastFolder = fldr.Name
            LastDate = fldr.DateLastModified
        End If
    Next
End Sub
This code works but I don't understand why an empty folder is a special case. A folder is a valid file system object whether it has items or now. Why would you chose to not initialize the $P and $C variables of a folder that's opened in a tab just because it has no files or folders? With this limitation removed, the "new project" automation can be more generic.

----------------------------
PJ in (a sleepy Sunday in) FL
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

Re: Parameters Not Initialized for Empty Folder

Post by FrizzleFry »

I have complained about this also.

There have been several scripts or user commands that I have had to come up with some workaround to get the current folder in the active pane/tab when there are no files/folders (or no focused item) in it.
User avatar
nikos
Site Admin
Site Admin
Posts: 15771
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Parameters Not Initialized for Empty Folder

Post by nikos »

$P etc rely on the selected item. But i'll see if anything can be done for paths only.
in the meantime you can use $L and make sure your scripts run from the left pane only
pj
Gold Member
Gold Member
Posts: 471
Joined: 2006 Jan 26, 14:01
Location: Florida

Re: Parameters Not Initialized for Empty Folder

Post by pj »

nikos wrote: 2018 Oct 29, 06:14 ...in the meantime you can use $L and make sure your scripts run from the left pane only
Please don't assume this will work in all cases. My usual workflow is LEFT/TOP is old, RIGHT/BOTTOM is new so I've been running scripts like this almost exclusively in the bottom pane.

Thanks for taking a look at this.

----------------------------
PJ in FL
pj
Gold Member
Gold Member
Posts: 471
Joined: 2006 Jan 26, 14:01
Location: Florida

Re: Parameters Not Initialized for Empty Folder

Post by pj »

UPDATE and related question

UPDATE:

Using Ultimate 4.4.0.1 x64, the $P variable is now initialized when the script is run against an empty folder.

Thank you! :D

However, the $C and $U variables are still uninitialized. :(
Arguments:
$P = [ F:\New Folder ]
$C = [ ]
$U = [ ]
$L = [ D:\INACTIVE PANE ]
$R = [ F:\New Folder ]

End of Arguments
Can the missing variables be added in an upcoming release, or is there a technical reason the variables aren't initialized?

As a work-around, $C and be derived in a script from $P, but $U contains information not available in any other variable.

Related question:

Display of user commands via menus ...
Customize > User Commands > Organize...
... can take nearly 20 seconds to show a list of 16 commands. :shock:

Repeating the menu immediately takes much less time, typically less than a second.

Is there some checking or validation of each command taking place? Could this be changed to eliminate the checking so each time the dialog is displayed it comes up quickly?

With external drives always attached to most of the computers I use x2 on, the delays to access those drives can sometimes take nearly 10 seconds each on the older USB drives. Skipping that, if that's the culprit, would be an improvement.

Thank you for taking time to review this post.

------------------
PJ in FL
User avatar
nikos
Site Admin
Site Admin
Posts: 15771
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Parameters Not Initialized for Empty Folder

Post by nikos »

usually delays in these lists are down to the icons, especially if they are extracted from network drives etc. Try using plain icons and if you need to use special icons, try getting them from somewhere local, e.g. shell32.dll
pj
Gold Member
Gold Member
Posts: 471
Joined: 2006 Jan 26, 14:01
Location: Florida

Re: Parameters Not Initialized for Empty Folder

Post by pj »

Using plain icons for every command defeats the purpose for icons in the first place, quickly finding the command button on the toolbar.

Can the icons be updated in background like the file/folder icons when a folder is opened?

----------------------------
PJ in FL
User avatar
nikos
Site Admin
Site Admin
Posts: 15771
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Parameters Not Initialized for Empty Folder

Post by nikos »

I will see how can this be improved
Post Reply