none
How to see all the files in a directory

    Question

  • I have an WXS installation procedure that successfully copies a file called powershell.exe.config into c:\windows\system32\windowspowershell\v1.0\.

    I know that it is successfull because I see the file using the "dired" feature in windows emacs. I can also use emacs to confirm that the contents are correct.

    HOWEVER, I CANNOT see this powershell.exe.config file in

    (1) windows explorer (even when I turn on the display

    (2) cmd.exe attrib or dir

    (3) powershell's dir

    How can I write a powershell program to display the file name correctly in the directory?

    thanks

    siegfried


    siegfried heintze

    Thursday, March 29, 2012 10:45 PM

All replies

  • Your files may be hidden

    Try: get-childitem -force

    You can also follow this procedure for Windows explorer: http://www.bleepingcomputer.com/tutorials/how-to-see-hidden-files-in-windows/ 


    Cyreli

    Thursday, March 29, 2012 11:35 PM
  • Cyreli: 

    thanks but neihter suggestion worked. I forgot to mention that this is Windows CE 7.

    Below is the output from the "dired" in emacs. I believe the 4th column is the owner name and the 3rd column is the group name? Notice how powershell.exe.config has owner name of "none" (what does that mean?) and is the only one in the group Administrators.

    How do I see this in powershell? How do I see the owner and group names in powershell and cmd.exe?

    thanks

    siegfried


    siegfried heintze

    Friday, March 30, 2012 12:43 AM
  • I do not see any screenshot

    Cyreli

    Friday, March 30, 2012 1:03 AM
  • Hi,

    Based on my test, there is no such file by default with in PowerShell 2.0. But we could create one manually based  on our requirement.

    Such as, we want to load .NET 4.0, then we should create a file “powershell.exe.config” in the C:\Windows\System32\WindowsPowerShell\v1.0
     Content:
     <?xml version="1.0"?>
    <configuration>
    	<startup useLegacyV2RuntimeActivationPolicy="true">
    		<supportedRuntime version="v4.0.30319"/>
    		<supportedRuntime version="v2.0.50727"/>
    	</startup>
    </configuration>
    

    For more details, I would like suggest you refer to the below link:

    Powershell 2 will not load my .NET 4 compiled assembiles?

    http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/4001dc42-8ce9-40df-b0d3-3d851696c9b5/

    Best Regards,

    Yan Li


    Yan Li

    TechNet Community Support

    Friday, March 30, 2012 1:21 AM
  • Ooops -- sorry! Here are the results from emacs:

      c:/Windows/System32/WindowsPowerShell/v1.0:
      total used in directory 1692 available 3991320
      drwxrwxrwx  1 TrustedInstaller TrustedInstaller      0 03-29 10:07 .
      drwxrwxrwx  1 SYSTEM           SYSTEM                0 2011-07-22  ..
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  27338 2009-06-10  Certificate.format.ps1xml
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller 126976 2009-07-13  CompiledComposition.Microsoft.PowerShell.GPowerShell.dll
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  27106 2009-06-10  Diagnostics.Format.ps1xml
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  72654 2009-06-10  DotNetTypes.format.ps1xml
      drwxrwxrwx  1 SYSTEM           SYSTEM                0 2011-07-22  Examples
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  24857 2009-06-10  FileSystem.format.ps1xml
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller 257847 2009-06-10  Help.format.ps1xml
      drwxrwxrwx  1 TrustedInstaller TrustedInstaller      0 2011-07-22  Modules
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  20480 2009-07-13  PSEvents.dll
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  89703 2009-06-10  PowerShellCore.format.ps1xml
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  18612 2009-06-10  PowerShellTrace.format.ps1xml
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  20120 2009-06-10  Registry.format.ps1xml
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  24498 2009-06-10  WSMan.Format.ps1xml
      drwxrwxrwx  1 TrustedInstaller TrustedInstaller      0 2011-07-22  en-US
      drwxrwxrwx  1 TrustedInstaller TrustedInstaller      0 2011-07-22  fr-FR
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  15603 2009-06-10  getevent.types.ps1xml
      -rwxrwxrwx  2 TrustedInstaller TrustedInstaller 452608 2009-07-13  powershell.exe
      -rw-rw-rw-  1 Administrators   None                213 03-28 10:26 powershell.exe.config
      -rwxrwxrwx  2 TrustedInstaller TrustedInstaller 204800 2009-07-13  powershell_ise.exe
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller 154624 2009-07-13  pspluginwkr.dll
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller   2048 2009-07-13  pwrshmsg.dll
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller  24064 2009-07-13  pwrshsip.dll
      -rw-rw-rw-  2 TrustedInstaller TrustedInstaller 168372 2009-06-10  types.ps1xml


    siegfried heintze

    Friday, March 30, 2012 4:31 PM
  • OK, I have a C++ program I wrote (some time ago) that uses WIN32_FIND_DATA and FindFirstFile/FindNextFile/FindClose to enumerate the files in a directory.

    This program correctly displays powershell.exe.config as does windows-emacs and cygwin ls (which I recently installed).

    Can someone please help me write a powershell program that will enumerate the contents of this directory so that powershell.exe.config will be displayed? Powershell dir/gci does not do this! CMD.EXE/dir also does not.

    Thanks!

    Siegfried


    siegfried heintze

    Wednesday, April 04, 2012 3:46 PM
  • you have the source code for the C++ app you wrote?
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, April 04, 2012 4:35 PM
  • OK, It is kinda overkill. The essence is just FindNextFile and WIN32_FIND_DATA. Here it is. I hope it is simpler in Powershell.

    Siegfried


    #include <fstream>
    #include <iostream>
    #include <sstream>
    #include <windows.h>
    #include <string>
    #include <cassert>
    #include <iomanip>
    #include <time.h>
    
    
    
    /****
     *  Recusively descend directory structure and take a snapshot of the directory structure and record
     *  the sizes.
     */
    
    
    
    /***
     *  Begin commands to execute this file using g++ with bash
     *  g++ -g -c DirSnapshot.cpp -o DirSnapshot.o
     *  g++ -g  DirSnapshot.o -o DirSnapshot.exe
     *  ./DirSnapshot.exe . cygwin_snapshot.txt
     *  cat cygwin_snapshot.txt
     *  End commands to execute this file using g++ with bash
     * 
     *  Begin commands to execute this file using MSVC10 with CMD.EXE
     *  rem cl DirSnapshot.cpp   /c /MLd /W3 /Gm /GX /ZI /Od /D WIN32 /D _DEBUG /D _CONSOLE /D _MBCS /FD /GZ /GR /D NOPROMPT
     *  cl DirSnapshot.cpp   /c /EHsc /D WIN32  /D _CONSOLE /D _MBCS /D NOPROMPT
     *  cl DirSnapshot.obj  /link /out:DirSnapshot.exe  /subsystem:console 
     *  DirSnapshot.exe /help
     *  DirSnapshot.exe . snapshot.dat 
     *  type  snapshot.dat 
     *  REM del *.obj DirSnapshot.exe *.ilk *.pdb *.idb
     *  End commands to execute this file using MSVC10 with CMD.EXE
     ***/
    
    #ifdef _MSC_VER
    #pragma warning(disable: 4786)
    #endif
    #if defined(_MSC_VER) && !defined(NOPROMPT)
    extern "C" int getch();
    #endif
    
    #ifdef unix
    #include <unistd.h>
    #include <stdio.h>
    #include <dirent.h>
    #include <string.h>
    #include <sys/stat.h>
    #endif
    
    using namespace std;
    //Traversing a Directory Hierarchy
    
    std::string commify(const std::string& sTmp){
      std::string sSize="";
      for(int jj=0,ii = sTmp.length()-1; ii >= 0; ii--,jj++){
        sSize=sTmp[ii]+sSize;
        if(jj%3 == 2){
          if(jj && ii){
            //if(dwSize==254055)    std::cout<<std::endl;
            sSize=","+sSize;
          }
        }
      }
      return sSize;
    }
    std::string commify(DWORD dwSize){
      std::ostringstream ossSize;
      ossSize <<dwSize;
      std::string sTmp = ossSize.str();
      if(dwSize>999){
        return commify(sTmp);
      }else 
        return sTmp;
    }
    std::string commify(const __int64& nSize){
      std::ostringstream ossSize;
      ossSize <<nSize;
      std::string sTmp = ossSize.str();
      return commify(sTmp);
    }
    //DWORD FileSize(const std::string& strNewPath){
    //      DWORD dwSize=0,dwHiSize=0;
    //      HANDLE hFile = ::CreateFile(strNewPath.c_str(),FILE_READ_ATTRIBUTES,
    //              FILE_SHARE_WRITE|FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
    //      if(INVALID_HANDLE_VALUE != hFile){
    //              dwSize = ::GetFileSize(hFile,&dwHiSize);
    //      }else {
    //              DWORD dwError = ::GetLastError();
    //              char pBuf[1024];
    //              ::FormatMessage(0,0,dwError,LANG_ENGLISH,(char*)&pBuf,0,0);
    //              std::cout<<pBuf<<std::endl;
    //              ::LocalFree(pBuf);
    //      }
    //      ::CloseHandle(hFile);
    //      return dwSize;
    //}
    void TraverseDirectory(std::ofstream& cout, std::string sPath, int nParent, DWORD* pdwParentSize, std::string strPattern){
    #ifdef unix
        DIR *dp;
        struct dirent *entry;
        struct stat statbuf;
        if((dp = opendir(sPath.c_str())) == NULL) {
          cerr << "cannot open directory "<< sPath.c_str() << std::endl;
          return;
        }
        chdir(sPath.c_str());
        while((entry = readdir(dp)) != NULL) {
          lstat(entry->d_name,&statbuf);
          DWORD dwSize=statbuf.st_blocks;
          if(S_ISDIR(statbuf.st_mode)) {
    	// Found a directory, but ignore . and .. 
    	if(strcmp(".",entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)
    	  continue;
    	cout << std::setw(nParent) << " " << entry->d_name << " ";
            ofstream::pos_type posSize = cout.tellp();
            cout << std::left << std::setw(20) << commify(dwSize*statbuf.st_blksize) <<std::endl;
    
    	// Recurse at a new indent level 
    	TraverseDirectory(cout, entry->d_name,nParent+1, &dwSize, strPattern);
    
            ofstream::pos_type posHere = cout.tellp();
            cout.seekp(posSize);
            cout << std::left << std::setw(20) << commify(dwSize*statbuf.st_blksize) << std::endl;
            cout.seekp(posHere);
          }
          else {
    	if(pdwParentSize)
    	  *pdwParentSize += dwSize; 
    	cout << std::setw(nParent) << " " << entry->d_name << " " << commify((DWORD)statbuf.st_blocks*statbuf.st_blksize) <<std::endl;
          }
        }
        chdir("..");
        closedir(dp);
    #else
      static const std::string dot = ".", dotdot = "..";
      WIN32_FIND_DATAA FindData;
      std::string strName = sPath + (sPath == "\\" ? "":"\\") + strPattern;
      HANDLE hFind;
      assert(hFind = FindFirstFileA(strName.c_str(), &FindData));
      //Traversing a Directory Hierarchy
      do{
        if(FindData.cFileName != dot && FindData.cFileName != dotdot){
          std::string strNewPath = sPath + (sPath == "\\" ? "" : "\\") +  FindData.cFileName;
          DWORD dwSize = FindData.nFileSizeLow;
          if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
            std::string strDirName = FindData.cFileName +   (std::string)"\\";
            cout << std::setw(nParent) << " " << FindData.cFileName<<" ";
            ofstream::pos_type posSize = cout.tellp();
            cout << std::left << std::setw(20) << commify(dwSize) << std::endl;
            TraverseDirectory(cout, strNewPath,   nParent+1, &dwSize, strPattern);
            ofstream::pos_type posHere = cout.tellp();
            cout.seekp(posSize);
            cout << std::left << std::setw(20) << commify(dwSize) << std::endl;
            cout.seekp(posHere);
          } else {
            cout << std::setw(nParent) << " " << FindData.cFileName << " " << commify(dwSize) << std::endl;
          }
          if(pdwParentSize){ 
            *pdwParentSize+= dwSize; 
          }
        } // if
      } while (FindNextFileA(hFind, &FindData));
      FindClose(hFind);
    #endif
    }
    static const char HOMEDRIVE[]="HOMEDRIVE", HOMEPATH[]="HOMEPATH";
    int main(int argc, char**argv, char**envp){
    	char* pHomeDrive=0,*pHomePath=0; int sz;
    	while(*envp){
    		if(!strncmp(HOMEDRIVE, *envp, sz=sizeof(HOMEDRIVE)/sizeof(HOMEDRIVE[0])-1))
    			pHomeDrive=*envp+sz+1;
    		else if(!strncmp(HOMEPATH, *envp, sz=sizeof(HOMEPATH)/sizeof(HOMEPATH[0])-1))
    			pHomePath = *envp+sz+1;
    		*envp++;			
    	}
      if(argc > 1 && (std::string)"/help" == argv[1]  
         || (std::string)"/help" == argv[1]  
         || (std::string)"-help" == argv[1]  
         || (std::string)"--help" == argv[1]){
        std::cout<<" usage "<<argv[0]<<" <directory> [<output file name>]\n"
          " Recurse directory structure and record a snapshot of the directory structure.\n"
          "\n"
          " This is designed to help you diagnose problems with disk \n"
          "   space magically dissappearing.\n"
          " If you don't specify the optional output file, \n"
          "   it will default to %HOMEDEVICE%\\%HOMEPATH%\\<date-time>.txt for windows machines.\n"
          "\n"
          " $Log: DirSnapshot.cpp,v $"
          " Revision 1.1  2011/03/30 19:54:41  v-siegfh"
          " Initial revision "
          "\n"
          " Revision 1.1  2005/08/23 00:02:05  Siegfried\n"
          " Initial revision\n"
          " \n"
                 << std::endl;
      }else{
        DWORD dwParentSize=0;
        char pcCurrentTime[255];
        time_t ct = time(0);
    #ifdef unix
    #else
    	char pPath[255]="";
    	strcat(strcat(strcat(pPath,pHomeDrive),pHomePath),"\\documents\\disk_space\\%Y_%m_%d_%H_%M_%a.txt");
    #endif
        strftime(pcCurrentTime, sizeof pcCurrentTime,
    #ifdef unix
                 "/c/DiskSpace/%Y_%m_%d_%H_%M_%a.txt",
    #else
                 pPath, //"%USERPROFILE%\\Documents\\disk_space\\%Y_%m_%d_%H_%M_%a.txt",
    #endif       
                 localtime(&ct));
        std::ofstream out(argc>2?argv[2]:pcCurrentTime);
        std::string dir(argc>1?argv[1]:
    #ifdef unix
                        "/c/"
    #else               
                        "C:\\"
    #endif
                        );
    #ifdef unix
    #else
        ULARGE_INTEGER FreeBytesAvailable={0,0},TotalNumberOfBytes={0,0},TotalNumberOfFreeBytes={0,0};
        if( GetDiskFreeSpaceExA(dir.c_str(),  &FreeBytesAvailable,  &TotalNumberOfBytes,  &TotalNumberOfFreeBytes  )){
        }else{  
          DWORD dwErr=GetLastError();
          out << " error = "<<dwErr<<std::endl;
        }
        out << "DirSnapshot V=1.0.0 start_directory="<< dir
            <<" Available="
            <<commify((__int64&)FreeBytesAvailable)
            <<" Total_Bytes="<<commify((__int64&)TotalNumberOfBytes)
            <<" Free_Bytes="<<commify((__int64&)TotalNumberOfFreeBytes)<< " sum_of_files= ";
    #endif
        ofstream::pos_type posHere = out.tellp();
        out << setw(20)<<commify(dwParentSize)<<endl;
        TraverseDirectory(out, dir, 1, &dwParentSize, "*.*");
        out.seekp(posHere);
        out << std::left<<std::setw(20)<<commify(dwParentSize)<<std::endl;
      }
      return 0;
    }
    





    siegfried heintze

    Thursday, April 05, 2012 4:43 AM
  • I'll see what I can whip out, but in the mean time take a look at this
     
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, April 05, 2012 5:02 PM
  • well that was fun, and only took 3 attempts! :)
     Add-Type -TypeDefinition @"
    using System;
    using System.Runtime.InteropServices;
     
    public class test3
    {
       [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
       public static extern IntPtr FindFirstFile(string lpFileName, ref
    WIN32_FIND_DATA lpFindFileData);
        [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
       public static extern bool FindNextFile(IntPtr hFindFile, ref
    WIN32_FIND_DATA lpFindFileData);
        [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
    public struct WIN32_FIND_DATA
    {
       public uint dwFileAttributes;
       public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
       public System.Runtime.InteropServices.ComTypes.FILETIME
    ftLastAccessTime;
       public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
       public uint nFileSizeHigh;
       public uint nFileSizeLow;
       public uint dwReserved0;
       public uint dwReserved1;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
       public string cFileName;
       [MarshalAs(UnmanagedType.ByValTStr, SizeConst=14)]
       public string cAlternateFileName;
    }
        public static WIN32_FIND_DATA FindFirstFile(string path, ref IntPtr ptr)
       {
           WIN32_FIND_DATA data = new WIN32_FIND_DATA();
           ptr = FindFirstFile(path, ref data);
           return data;
       }
    }
    "@
      $a = new-object IntPtr
    $rtn = [test3]::FindFirstFile('c:\ps\*', [ref]$a)
    $rtn.cFileName
    while([test3]::FindNextFile($a, [ref] $rtn)){$rtn.cFileName}
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, April 05, 2012 5:55 PM
  • Wow! Thanks Justin!

    What am I doing wrong? I changed the file name with the wild card just a little. I'm using windows 7.

    $rtn = [test3]::FindFirstFile('.\*', [ref]$a)
    

    I get these errors:

    Cannot find an overload for "FindFirstFile" and the argument count: "2".
    
    At F:\backup\unison\WinOOP\Examples\powershell\psdir.ps1:52 char:30
    
    + $rtn = [test3]::FindFirstFile <<<< ('.\*', [ref]$a)
    
        + CategoryInfo          : NotSpecified: (:) [], MethodException
    
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    
     
    
    
    [ref] cannot be applied to a variable that does not exist.
    
    At F:\backup\unison\WinOOP\Examples\powershell\psdir.ps1:54 char:43
    
    + while([test3]::FindNextFile($a, [ref] $rtn <<<< )){
    
        + CategoryInfo          : InvalidOperation: (rtn:Token) [], RuntimeExcepti 
    
       on
    
        + FullyQualifiedErrorId : NonExistingVariableReference
    
     
    
    end


    siegfried heintze

    Thursday, April 05, 2012 11:18 PM
  • $a = ""

    says it in the msg, cant do ref to a null value, assign anything to it..

    
    

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 06, 2012 1:47 AM
  • Well shucks Rich! I'm confused.

    When I run my C++ program on the directory (as I explained above), it lists powershell.exe.config. When I run yours (which is calling the same functions) it does not. It correctly lists all the other files, of course.

    So... I think this means that there is something about powershell or .NET Framework that is doing some filtering?

    Does anyone have any ideas?

    Thanks,

    Siegfried


    siegfried heintze

    Tuesday, April 10, 2012 2:22 PM
  • I made some shocking discoveries today:

    (1) When I use c:\windows\syswow64\cmd.exe to execute "copy powershell.exe.config c:\windows\system32\windowspowershell\v1.0\" I cannot see the resulting file (c:\windows\system32\windowspowershell\v1.0\powershell.exe.cofig) using c:\windows\system32\cmd.exe dir.

    (2) I can see it using c:\windows\syswow64\cmd dir however!

    (3) I cannot see it with Justin's program above when running it from c:\windows\system32\cmd.exe and c:\windows\system32\windowspowershell\1.0\powershell.exe. I should try running it from c:\windows\syswow64\cmd.exe.

    (4) I can see it using emacs from c:\windows\system32\cmd.exe!

    (5) I can see it using a native c++ program (posted above) when run from c:\windows\sytem32\cmd.exe.

    What the heck is going on here? How can I enhance justin's program so I can run it from c:\windows\syswow64\cmd.exe and see my file?

    Thanks

    Siegfried


    siegfried heintze

    Friday, April 13, 2012 4:32 AM
  • there are certain folders that are masked, this is one of them.... so where
    you think its looking, is not actually where its looking...
     
    when you run the 32 bit version (from syswow64) and you go to
    c:\windows\system32\....
     
    you're actually in c:\windows\syswow64
     
    is there a way to access the 64bit system32 folder from a 32 bit process? im
    not sure, I know there is from the registry but im not sure about the file
    system... I assume there is..
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, April 13, 2012 12:30 PM