WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Version and Dir Mgmt

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

File and Folder Properties Tool

 Keywords: File Folder Properties Tool Right Click Menu Short Filename Created Modified Accessed

This is a little tool the displays frequently needed file and folder properties. Yes, it's a bit redundant, but it does offer some handy features such as an easy way to get a file or folder's short path to the clipboard. This program uses code that dynamically resizes and centers the dialog based on the width of the text, without resorting to a fixed width font.
; Add File/Folder Properties to Explorer Right-Click
; Version 1.0
; Les Ferch, July 10, 2008

IntControl(1002,0,0,0,0) ; Do not show icon
IntControl(12,5,0,0,0) ; Terminate silently
IntControl(1003,0,0,0,0) ; No WinBatch processing window
Title = "File/Folder Properties"

#DefineFunction AdminUser()
Admin = @FALSE
ErrMode = ErrorMode(@OFF)
RegSetValue(@REGMACHINE,"System\CurrentControlSet\Control[Admin]","1")
Admin = RegQueryValue(@REGMACHINE,"System\CurrentControlSet\Control[Admin]")
RegDelValue(@REGMACHINE,"System\CurrentControlSet\Control[Admin]")
ErrorMode(ErrMode)
If Admin=="1" Then Admin = @TRUE
Return Admin
#EndFunction

If RtStatus()==10 Then
   Param1 = "C:\Program Files\Common Files\Microsoft Shared\Stationery"
EndIf

If !IsDefined(Param1)
   If AdminUser()
      FileKey = "*\Shell\File Properties"
      DirKey = "Directory\Shell\Folder Properties"
      FileVal = FileKey:"\Command[]"
      DirVal = DirKey:"\Command[]"
      Prefix = ""
      MyPath = IntControl(1004,0,0,0,0)
      If StrLower(FileExtension(MyPath))!="exe" Then Prefix = "WinBatch.exe "
      Cmd = Prefix:'"':MyPath:'" "%%1"'
      ErrMode = ErrorMode(@OFF)
      C1 = RegQueryValue(@REGCLASSES,FileVal)
      C2 = RegQueryValue(@REGCLASSES,DirVal)
      ErrorMode(ErrMode)
      If C1!=Cmd || C2!=Cmd
         Ans = AskYesNo(Title,"Add this program to file/folder right-click?")
         If Ans==@YES Then
            RegSetValue(@REGCLASSES,FileVal,Cmd)
            RegSetValue(@REGCLASSES,DirVal,Cmd)
         EndIf
      Else
         Ans = AskYesNo(Title,"Remove this program from file/folder right-click?")
         If Ans==@YES Then
            RegDeleteKey(@REGCLASSES,FileKey)
            RegDeleteKey(@REGCLASSES,DirKey)
         EndIf
      EndIf
   EndIf
   Exit
EndIf

Item = Param1

AddExtender("wwctl44i.dll")

#DefineSubRoutine GetTextWidth(Text,UseFontHandle)
TextLen = StrCharCount(Text)
WM_GETFONT = 49 ; Gets first font used in dialog
If UseFontHandle Then hFont = SendMessageA(ControlHandle,WM_GETFONT,0,0)
HDC = DllCall(StrCat(DirWindows(1),'USER32.DLL'),long:'GetDC',lpnull)
If UseFontHandle
   hOldFont = DllCall(StrCat(DirWindows(1),"GDI32.DLL"),long:"SelectObject",long:HDC,long:hFont)
   DllCall(StrCat(DirWindows(1),'GDI32.DLL'),long:'SelectObject',long:HDC,long:hFont)
EndIf
lpsize = BinaryAlloc(8)
result = DllCall(StrCat(DirWindows(1),'GDI32.DLL'),long:'GetTextExtentPoint32A',long:HDC,lpstr:Text,long:TextLen,lpbinary:lpsize)
cx = BinaryPeek4(lpsize,0) ; Width
cy = BinaryPeek4(lpsize,4) ; Height (not using this)
If UseFontHandle Then DllCall(StrCat(DirWindows(1),"GDI32.DLL"),long:"SelectObject",long:HDC,long:hOldFont)
DllCall(StrCat(DirWindows(1),'USER32.DLL'),long:'ReleaseDC',lpnull,long:HDC)
Return cx
#EndSubRoutine

File = FileExist(Item)
Folder = DirExist(Item)
If !File && !Folder Then Exit

oFSO = ObjectCreate("Scripting.FileSystemObject")

If File
   oItem = oFSO.GetFile(Item)
   Title = "File Properties:"
EndIf
If Folder
   oItem = oFSO.GetFolder(Item)
   Title = "Folder Properties:"
EndIf

#DefineFunction DateFormat(Date)
Date = StrSub(Date,1,4):"-":StrSub(Date,6,2):"-":StrSub(Date,9,2):" ":StrSub(Date,12,-1)
Return Date
#EndFunction

ItemLongPath = oItem.Path
ItemShortPath = oItem.ShortPath
ItemCreated = DateFormat(oItem.DateCreated)
ItemLastModified = DateFormat(oItem.DateLastModified)
ItemLastAccessed = DateFormat(oItem.DateLastAccessed)

ChkFP = 1
LPLen = GetTextWidth(ItemLongPath,@FALSE)
SPLen = GetTextWidth(ItemShortPath,@FALSE)
Text = ItemLongPath
If SPLen>LPLen Then Text = ItemShortPath

MSG_INIT = 0
RET_DO_DEFAULT = -1

#DefineSubRoutine MainDlgProc(MainDlg_Handle,MainDlg_Message,MainDlg_ID,MainDlg_EventInfo,rsvd)
Switch MainDlg_Message
Case MSG_INIT
   ControlHandle = cWndbyid(MainDlg_Handle,102)
   cx = GetTextWidth(Text,@TRUE)
   Pos = WinPlaceGet(@NORMAL,Title)
   A1 = ItemExtract(1,Pos," ")
   B1 = ItemExtract(2,Pos," ")
   C1 = ItemExtract(3,Pos," ")
   D1 = ItemExtract(4,Pos," ")
   C2 = Int((49 * WinMetrics(-5) + cx) * 1.0 / WinMetrics(0) * 1000) + A1 + 10
   C2 = Max(C1,C2)
   HalfDif = (C2 - C1) / 2
   A2 = A1 - HalfDif
   C2 = C2 - HalfDif
   If A2<0
      C2 = C2 - A2
      A2 = 0
   EndIf
   WinPlaceSet(@NORMAL,Title,A2:" ":B1:" ":C2:" ":D1)
   Return RET_DO_DEFAULT
EndSwitch
#EndSubRoutine

Font = "DEFAULT"
MainDlgFormat = `WWWDLGED,6.1`
MainDlgCaption = Title
MainDlgX = 9999
MainDlgY = 9999
MainDlgWidth = 150
MainDlgHeight = 110
MainDlgNumControls = 013
MainDlgProcedure = `MainDlgProc`
MainDlgFont = `DEFAULT`
MainDlgTextColor = `DEFAULT`
MainDlgBackground = `DEFAULT,DEFAULT`
MainDlgConfig = 0
MainDlg001 = `000,000,000,000,STATICTEXT,DEFAULT,DEFAULT,DEFAULT,3,DEFAULT,`:Font:`,"0|0|0",DEFAULT` ; For WM_GETFONT
MainDlg002 = `007,090,088,012,PUSHBUTTON,DEFAULT,"Copy Selected Items to Clipboard",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MainDlg003 = `100,090,040,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg004 = `007,005,038,012,CHECKBOX,ChkFP,"Full Path:",1,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg005 = `007,020,038,012,CHECKBOX,ChkSP,"Short Path:",1,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg006 = `007,035,036,012,CHECKBOX,ChkCr,"Created:",1,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg007 = `007,050,036,012,CHECKBOX,ChkLM,"Modified:",1,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg008 = `007,065,038,012,CHECKBOX,ChkLA,"Accessed:",1,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg009 = `049,008,999,012,VARYTEXT,ItemLongPath,DEFAULT,DEFAULT,8,DEFAULT,`:Font:`,"0|0|0",DEFAULT`
MainDlg010 = `049,024,999,012,VARYTEXT,ItemShortPath,DEFAULT,DEFAULT,9,DEFAULT,`:Font:`,"0|0|0",DEFAULT`
MainDlg011 = `049,038,100,012,VARYTEXT,ItemCreated,DEFAULT,DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg012 = `049,053,100,012,VARYTEXT,ItemLastModified,DEFAULT,DEFAULT,11,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MainDlg013 = `049,068,100,012,VARYTEXT,ItemLastAccessed,DEFAULT,DEFAULT,12,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed = Dialog("MainDlg")

Data = ""
If ChkFP Then Data = Data:ItemLongPath:@TAB
If ChkSP Then Data = Data:ItemShortPath:@TAB
If ChkCr Then Data = Data:ItemCreated:" (Created)":@TAB
If ChkLM Then Data = Data:ItemLastModified:" (Modified)":@TAB
If ChkLA Then Data = Data:ItemLastAccessed:" (Accessed)":@TAB
Data = StrTrim(Data)
Data = StrReplace(Data,@TAB,@CRLF)

ClipPut(Data)

Article ID:   W18261
Filename:   File and Folder Properties Tool.txt
File Created: 2008:07:11:10:33:24
Last Updated: 2008:07:11:10:33:24