locked
Print contents of Windows Explorer window in XP RRS feed

  • Question

  • Hi everyone,

    I've found lots of posts about using the command prompt to export filenames to a .csv file to open in Excel and then print, and this accomplishes half of what I need. I'm trying to essentially print screen for the entire contents of a Windows Explorer window. In this case there are thousands of audio files in this folder and I need not only the filename but the length (minutes:seconds) as well. This displays easily in Windows Explorer but does not come through when using dir in the command prompt. I know that I could print screen, then scroll, then print screen again, but like I said there are THOUSANDS of files here and that would take all day. There has to be an easier way. Exporting to Excel would be ideal but sending directly to the printer would work as well. Thanks so much for any advice!

    Friday, July 12, 2013 4:46 PM

Answers

  • Below is an HTA that will let you browse to a folder then when you click on "List Files" it will generate an excel file on your desktop. First column is the filename and durations (if they exist) will be in the second column.

    I am afraid I don't have Office installed on XP here so this has only been tested on Windows 7.

    The script also does not search sub-folders - it will only list the files that are in the parent folder you have chosen.

    Save everything below in Notepad with a .hta file extension. Double click the saved file to run.

    (If you see either a vertical scrollbar or a white space at the bottom - look for the window.resizeTo statement in the script and adjust the second value until there is neither scrollbar nor white space. Tested the layout on three machines, each with a different theme, and each takes a different value.)

    Have fun!

    <!-- ////////////////////////////////////////////////////////////////////////////// HTA to build an Excel file on the desktop. To use, simply copy this into Notepad and use "File -> Save As" and in the dialog that opens: - change the "Save as type" to All Files(*.*) - choose a name and add the .hta file extension - choose where to save it - click Save Double click on the saved hta file to use it. The first column is the filename. If the tip info for the file contains a "Length" (Windows 7) or a "Duration" (Windows XP), then this value will be put into the second column. Tested on Windows 7 only. mystifeid ////////////////////////////////////////////////////////////////////////////// --> <html> <head> <title>FileName HTA</title> <HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Filename To Excel" SHOWINTASKBAR="yes" ICON="shutdown.ico" CONTEXTMENU="yes" SCROLL="no" SCROLLFLAT="no" SELECTION="no" SINGLEINSTANCE="yes" SYSMENU="no" > <meta http-equiv="x-ua-compatible" content="ie=9"> <style type="text/css"> html {font:100%;} body {text-align:center;font-family:Arial,sans-serif;margin:0;padding:0 0 24px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#0088ff', EndColorStr='#222222');} h1 {color:#aaccff;font-size:18px;line-height:22px;font-weight:bold;margin:10px 0 0 26px;} button {width:150px;font-size:16px;line-height:20px;display:block;} button {margin:20px auto 0;border:1px solid #000000;color:#acf;cursor:pointer;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#222222', EndColorStr='#0088ff');} button:hover {color:#9be;} #wClose {width:15px;height:16px;margin:0 10px 0 0;padding:0;float:right;color:#ddd;background:transparent;border:1px solid #ddd;cursor:pointer;} #wClose:hover {color:#f00;} </style> <script type="text/jscript"> function browseForFolder(){ var objFolder, objShell=new ActiveXObject("shell.application"); objFolder=objShell.BrowseForFolder(0, "List Files In Selected Folder", 0x210); if(objFolder!==null){ selectFolder.value=objFolder.self.Path; } objShell=null; } function saveFile(){ var sPath, wshShell, sheet, workBook, exlApp, i=0, j, oItem, matches, objFolder, objFolderItems, objShell=new ActiveXObject("shell.application"), re=/^Duration: |Length: (.+?)$/m; objFolder=objShell.NameSpace(selectFolder.value); if (objFolder!==null){ objFolderItems=objFolder.Items(); if(objFolderItems!==null){ exlApp = new ActiveXObject("Excel.Application"); exlApp.SheetsInNewWorkBook=1; exlApp.Visible=false; exlApp.DisplayAlerts=false; workBook=exlApp.workBooks.Add(); sheet=workBook.ActiveSheet; sheet.Cells(1, 1).Value="FileName"; sheet.Cells(1, 2).Value="Duration"; j=objFolderItems.Count; for(i;i<j;i++){ oItem=objFolderItems.Item(i); sheet.Cells(i+2, 1).Value=oItem.Name; matches=re.exec(objFolder.GetDetailsOf(oItem, -1)); if(matches!==null){ sheet.Cells(i+2, 2).Value=matches[1]; } } objShell=null; wshShell=new ActiveXObject("WScript.Shell"); sPath=wshShell.SpecialFolders("Desktop"); workBook.SaveAs(sPath+"\\songs.xlsx"); exlApp.Quit(); exlApp=null; wshShell=null; } } } function fx(){ //if you see either a scrollbar or a white space at the bottom of the hta, adjust the second value in the window.resizeTo statement below window.resizeTo(308,204); window.moveTo ((screen.width/2-204),(screen.height/2-200)) listFiles.onclick=saveFile; browse.onclick=browseForFolder; wClose.onclick=function(){close();}; } document.onreadystatechange=function(){ if(document.readyState==="complete"){ fx(); } }; </script> </head> <body> <div id="choices"> <div id="wClose">X</div> <h1>Choose Folder</h1> <input type="text" id="selectFolder"></input> <button type="button" id="browse">Browse</button> <button type="button" id="listFiles">List Files</button> </div> </body> </html>





    • Edited by mystifeid Saturday, July 13, 2013 1:37 AM restyle - code entry deletes absolute positioning
    • Proposed as answer by arnavsharmaModerator Sunday, July 21, 2013 8:43 AM
    • Marked as answer by Nellie1978 Sunday, July 21, 2013 8:20 PM
    Saturday, July 13, 2013 12:32 AM

All replies

  • Below is an HTA that will let you browse to a folder then when you click on "List Files" it will generate an excel file on your desktop. First column is the filename and durations (if they exist) will be in the second column.

    I am afraid I don't have Office installed on XP here so this has only been tested on Windows 7.

    The script also does not search sub-folders - it will only list the files that are in the parent folder you have chosen.

    Save everything below in Notepad with a .hta file extension. Double click the saved file to run.

    (If you see either a vertical scrollbar or a white space at the bottom - look for the window.resizeTo statement in the script and adjust the second value until there is neither scrollbar nor white space. Tested the layout on three machines, each with a different theme, and each takes a different value.)

    Have fun!

    <!-- ////////////////////////////////////////////////////////////////////////////// HTA to build an Excel file on the desktop. To use, simply copy this into Notepad and use "File -> Save As" and in the dialog that opens: - change the "Save as type" to All Files(*.*) - choose a name and add the .hta file extension - choose where to save it - click Save Double click on the saved hta file to use it. The first column is the filename. If the tip info for the file contains a "Length" (Windows 7) or a "Duration" (Windows XP), then this value will be put into the second column. Tested on Windows 7 only. mystifeid ////////////////////////////////////////////////////////////////////////////// --> <html> <head> <title>FileName HTA</title> <HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Filename To Excel" SHOWINTASKBAR="yes" ICON="shutdown.ico" CONTEXTMENU="yes" SCROLL="no" SCROLLFLAT="no" SELECTION="no" SINGLEINSTANCE="yes" SYSMENU="no" > <meta http-equiv="x-ua-compatible" content="ie=9"> <style type="text/css"> html {font:100%;} body {text-align:center;font-family:Arial,sans-serif;margin:0;padding:0 0 24px;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#0088ff', EndColorStr='#222222');} h1 {color:#aaccff;font-size:18px;line-height:22px;font-weight:bold;margin:10px 0 0 26px;} button {width:150px;font-size:16px;line-height:20px;display:block;} button {margin:20px auto 0;border:1px solid #000000;color:#acf;cursor:pointer;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#222222', EndColorStr='#0088ff');} button:hover {color:#9be;} #wClose {width:15px;height:16px;margin:0 10px 0 0;padding:0;float:right;color:#ddd;background:transparent;border:1px solid #ddd;cursor:pointer;} #wClose:hover {color:#f00;} </style> <script type="text/jscript"> function browseForFolder(){ var objFolder, objShell=new ActiveXObject("shell.application"); objFolder=objShell.BrowseForFolder(0, "List Files In Selected Folder", 0x210); if(objFolder!==null){ selectFolder.value=objFolder.self.Path; } objShell=null; } function saveFile(){ var sPath, wshShell, sheet, workBook, exlApp, i=0, j, oItem, matches, objFolder, objFolderItems, objShell=new ActiveXObject("shell.application"), re=/^Duration: |Length: (.+?)$/m; objFolder=objShell.NameSpace(selectFolder.value); if (objFolder!==null){ objFolderItems=objFolder.Items(); if(objFolderItems!==null){ exlApp = new ActiveXObject("Excel.Application"); exlApp.SheetsInNewWorkBook=1; exlApp.Visible=false; exlApp.DisplayAlerts=false; workBook=exlApp.workBooks.Add(); sheet=workBook.ActiveSheet; sheet.Cells(1, 1).Value="FileName"; sheet.Cells(1, 2).Value="Duration"; j=objFolderItems.Count; for(i;i<j;i++){ oItem=objFolderItems.Item(i); sheet.Cells(i+2, 1).Value=oItem.Name; matches=re.exec(objFolder.GetDetailsOf(oItem, -1)); if(matches!==null){ sheet.Cells(i+2, 2).Value=matches[1]; } } objShell=null; wshShell=new ActiveXObject("WScript.Shell"); sPath=wshShell.SpecialFolders("Desktop"); workBook.SaveAs(sPath+"\\songs.xlsx"); exlApp.Quit(); exlApp=null; wshShell=null; } } } function fx(){ //if you see either a scrollbar or a white space at the bottom of the hta, adjust the second value in the window.resizeTo statement below window.resizeTo(308,204); window.moveTo ((screen.width/2-204),(screen.height/2-200)) listFiles.onclick=saveFile; browse.onclick=browseForFolder; wClose.onclick=function(){close();}; } document.onreadystatechange=function(){ if(document.readyState==="complete"){ fx(); } }; </script> </head> <body> <div id="choices"> <div id="wClose">X</div> <h1>Choose Folder</h1> <input type="text" id="selectFolder"></input> <button type="button" id="browse">Browse</button> <button type="button" id="listFiles">List Files</button> </div> </body> </html>





    • Edited by mystifeid Saturday, July 13, 2013 1:37 AM restyle - code entry deletes absolute positioning
    • Proposed as answer by arnavsharmaModerator Sunday, July 21, 2013 8:43 AM
    • Marked as answer by Nellie1978 Sunday, July 21, 2013 8:20 PM
    Saturday, July 13, 2013 12:32 AM
  • Sorry, forgot that the code block on this forum deletes any absolute positioning, so if you tried this before now, it would have looked strange. I have now updated what is above.
    Saturday, July 13, 2013 1:40 AM
  • Thank you! I will try this out tomorrow.
    Monday, July 15, 2013 1:13 AM
  • Looks like it works. My friend tried it out on an XP machine with Office 2003 and said that the Excel file would open but appeared blank. He sent it to me and I opened it in Office 2010 with only a few hiccups - looks like I have to have Excel already open in order to open the file. Either way, thank you so much! This will save me hours and hours!
    Saturday, July 20, 2013 8:33 PM
  • For use with Office 2003, try saving the file with an xls extension instead of xlsx.

    Look for this line

    workBook.SaveAs(sPath+"\\songs.xlsx");

    and change to

    workBook.SaveAs(sPath+"\\songs.xls");

    Sunday, July 21, 2013 1:15 AM