Parameters Not Initialized for Empty Folder

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

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

Parameters Not Initialized for Empty Folder

Post by pj » 2018 Oct 28, 00:24

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: 14482
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Parameters Not Initialized for Empty Folder

Post by nikos » 2018 Oct 28, 05:45

this is by design
when does it become a problem for you?

pj
Gold Member
Gold Member
Posts: 396
Joined: 2006 Jan 26, 14:01
Location: Florida

Re: Parameters Not Initialized for Empty Folder

Post by pj » 2018 Oct 28, 21:43

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: 1143
Joined: 2005 Oct 16, 19:09

Re: Parameters Not Initialized for Empty Folder

Post by FrizzleFry » 2018 Oct 29, 04:57

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: 14482
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: Parameters Not Initialized for Empty Folder

Post by nikos » 2018 Oct 29, 06:14

$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: 396
Joined: 2006 Jan 26, 14:01
Location: Florida

Re: Parameters Not Initialized for Empty Folder

Post by pj » 2018 Oct 29, 11:05

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

Post Reply