Exemple #1
0
def launch_file_explorer(path, files):
    '''
	Given a absolute base path and names of its children (no path), open
	up one File Explorer window with all the child files selected
	
	Taken from http://mail.python.org/pipermail/python-win32/2012-September/012533.html
	'''
    files = [os.path.basename(f) for f in files]
    # folder_pidl = shell.SHILCreateFromPath(path,0)[0]
    folder_pidl = shell.SHGetDesktopFolder().ParseDisplayName(0, 0, path)
    # folder_pidl = shell.SHParseDisplayName(path,0)[0]

    desktop = shell.SHGetDesktopFolder()
    shell_folder = desktop.BindToObject(folder_pidl, None,
                                        shell.IID_IShellFolder)
    name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
                                 for item in shell_folder])
    to_show = []
    for file in files:
        if name_to_item_mapping.has_key(file):
            to_show.append(name_to_item_mapping[file])
        # else:
        # raise Exception('File: "%s" not found in "%s"' % (file, path))

    shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
Exemple #2
0
def main(all_images):
    """
    Find a connected iPhone, and print the paths to images on it.
    :param all_images: Whether or not to list all images on the phone, or
                       only those newer than those found on disk.
    """
    start_time = time.time()
    localdir = os.path.abspath(os.path.dirname(sys.argv[0]))
    desktop = shell.SHGetDesktopFolder()

    # Find the iPhone in the Virtual Folder "Computer"
    for pidl in desktop.EnumObjects(0, shellcon.SHCONTF_FOLDERS):
        if desktop.GetDisplayNameOf(pidl, shellcon.SHGDN_NORMAL) == "Computer":
            folder = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
            for dpidl in folder:
                # If this is the iPhone, get the PIDL of its DCIM folder.
                dcim_pidl, parent, iphone_name = get_dcim_folder(dpidl, folder)
                if dcim_pidl is not None:
                    if all_images:
                        prev_index = -1
                    else:
                        dest = get_destination_for_phone(localdir, iphone_name)
                        prev_index = get_prev_image(dest)
                    walk_dcim_folder(dcim_pidl, parent, prev_index)
                    break
            break
    v_print("Done. That took %1.2fs." % (time.time() - start_time))
Exemple #3
0
def get_computer_shell_folder():
    """
    Return the local computer's shell folder.
    """
    desktop = shell.SHGetDesktopFolder()
    log.debug(u"desktop: %s", desktop)
    candidates = list()

    for pidl in desktop.EnumObjects(0, shellcon.SHCONTF_FOLDERS):
        display_name = desktop.GetDisplayNameOf(pidl, shellcon.SHGDN_NORMAL)
        log.debug(u"desktop folder: %s", display_name)

        some_obj = desktop.BindToObject(pidl, None, shell.IID_IShellFolder2)
        if is_my_computer_path_obj(some_obj):
            log.info(u"LOOKS LIKE MyComputer: %s", display_name)
            candidates.append(some_obj)

    if not candidates:
        console("ERROR: cant find My Computer")
        sys.exit(1)

    if len(candidates) > 1:
        console(u"ERROR: too many candidates to My Computer (%d): %s" %
                (len(candidates), candidates))
        sys.exit(1)

    return candidates[0]
Exemple #4
0
def get_my_documents():
    """Return the My Documents folder"""
    # See:
    # http://msdn.microsoft.com/en-us/library/windows/desktop/bb776887%28v=vs.85%29.aspx#mydocs
    # http://msdn.microsoft.com/en-us/library/bb762494%28v=vs.85%29.aspx#csidl_personal

    try:
        df = shell.SHGetDesktopFolder()
        pidl = df.ParseDisplayName(
            0, None, "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
    except pywintypes.com_error as e:
        if e.hresult == winerror.E_INVALIDARG:
            # This error occurs when the My Documents virtual folder is not available below the Desktop virtual folder in the file system.
            # This may be the case if it has been made unavailable using a Group Policy setting.
            # See http://technet.microsoft.com/en-us/library/cc978354.aspx.
            pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_PERSONAL)
        else:
            raise
    mydocs = shell.SHGetPathFromIDList(pidl)

    # TODO: may need to handle window-specific encoding here.
    #encoding = locale.getdefaultlocale()[1]
    #if encoding is None:
    #    encoding = "utf-8"

    return mydocs
Exemple #5
0
    def json_recycle_bin(self):
        if self.destination == 'local':
            with open(
                    self.output_dir + self.computer_name + '_recycle_bin' +
                    self.rand_ext, 'wb') as output:
                json_writer = get_json_writer(output)
                header = ["COMPUTER_NAME", "TYPE", "NAME_1", "NAME_2"]
                idl = shell.SHGetSpecialFolderLocation(
                    0, shellcon.CSIDL_BITBUCKET)
                desktop = shell.SHGetDesktopFolder()
                files = desktop.BindToObject(idl, None, shell.IID_IShellFolder)

                for bin_file in files:
                    write_to_json(header,
                                  [
                                      self.computer_name, 'recycle_bin',
                                      files.GetDisplayNameOf(
                                          bin_file, shellcon.SHGDN_NORMAL),
                                      files.GetDisplayNameOf(
                                          bin_file, shellcon.SHGDN_FORPARSING)
                                  ], json_writer)
                close_json_writer(json_writer)
        record_sha256_logs(
            self.output_dir + self.computer_name + '_recycle_bin' +
            self.rand_ext,
            self.output_dir + self.computer_name + '_sha256.log')
Exemple #6
0
    def __init__(self):
        """
        self.fs:    A RAM based filesystem that is the heart of the server fs
            May be converted into another system if memory requirements become too large
        self.programFS: OS FIlesystem representing the program files
        self.userFS:    OS Filesystem representing the user ~ files
        TODO: How to handle save and loads?
        """
        print "Loading files"
        self.fs = fs.memoryfs.MemoryFS()
        self.programFS = fs.osfs.OSFS(".")

        # We need to identify what os we are in, and generate the correct path
        if os.name == "nt":
            from win32com.shell import shell
            df = shell.SHGetDesktopFolder()
            pidl = df.ParseDisplayName(
                0, None, "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
            userPath = shell.SHGetPathFromIDList(pidl)
        else:
            userPath = os.path.expanduser("~")

        userPath += "/CityMania/"
        if not os.path.isdir(userPath):
            os.makedirs(userPath + "Maps/")

        self.userFS = fs.osfs.OSFS(userPath)

        self.loadFS()
Exemple #7
0
def launch_file_explorer(path, files=None):
    '''
	Given a absolute base path and names of its children (no path), open
	up one File Explorer window with all the child files selected
	
	Taken from http://mail.python.org/pipermail/python-win32/2012-September/012533.html
	'''
    if not files:
        path, files = os.path.split(path)
        files = [files]
    else:
        files = [os.path.basename(f) for f in files]

    if sys.getwindowsversion().major == 5:  #if windows xp
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(folder_pidl, None,
                                            shell.IID_IShellFolder)
        name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
                                     for item in shell_folder])
        to_show = []
        for f in files:
            if name_to_item_mapping.has_key(f):
                to_show.append(name_to_item_mapping[f])
            # else:
            # raise Exception('f: "%s" not found in "%s"' % (f, path))

        shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
    else:  # no SHILCreateFromPath in windows 7
        f = os.path.join(path, files[0])
        f_mbcs = f.encode('mbcs')
        if os.path.exists(f_mbcs):
            os.system(r'explorer /select,"%s"' % f_mbcs)
        else:
            os.startfile(path)
Exemple #8
0
def show_files_win32(path, files):
    """Takes a path to a directory and a list of filenames in that directory
    to display.

    Returns True on success.
    """

    assert os.name == "nt"

    import pywintypes
    from win32com.shell import shell

    assert is_fsnative(path)
    assert all(is_fsnative(f) for f in files)

    normalized_files = map(normalize_path, files)

    try:
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(
            folder_pidl, None, shell.IID_IShellFolder)
        items = []
        for item in shell_folder:
            name = desktop.GetDisplayNameOf(item, 0)
            if normalize_path(name) in normalized_files:
                items.append(item)
        shell.SHOpenFolderAndSelectItems(folder_pidl, items, 0)
    except pywintypes.com_error:
        return False
    else:
        return True
Exemple #9
0
    def __init__(self):
        message_map = {
                win32con.WM_DESTROY: self.OnDestroy,
                win32con.WM_COMMAND: self.OnCommand,
                win32con.WM_SIZE: self.OnSize,
        }
        # Register the Window class.
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32api.GetModuleHandle(None)
        wc.lpszClassName = "test_explorer_browser"
        wc.lpfnWndProc = message_map # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(wc)
        # Create the Window.
        style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_VISIBLE
        self.hwnd = win32gui.CreateWindow( classAtom, "Python IExplorerBrowser demo", style, \
                0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
                0, 0, hinst, None)
        eb = pythoncom.CoCreateInstance(shellcon.CLSID_ExplorerBrowser, None, pythoncom.CLSCTX_ALL, shell.IID_IExplorerBrowser)
        # as per MSDN docs, hook up events early
        self.event_cookie = eb.Advise(wrap(EventHandler()))

        eb.SetOptions(shellcon.EBO_SHOWFRAMES)
        rect = win32gui.GetClientRect(self.hwnd)
        # Set the flags such that the folders autoarrange and non web view is presented
        flags = (shellcon.FVM_LIST, shellcon.FWF_AUTOARRANGE | shellcon.FWF_NOWEBVIEW)
        eb.Initialize(self.hwnd, rect, (0, shellcon.FVM_DETAILS))
        if len(sys.argv)==2:
            # If an arg was specified, ask the desktop parse it.
            # You can pass anything explorer accepts as its '/e' argument -
            # eg, "::{guid}\::{guid}" etc.
            # "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" is "My Computer"
            pidl = shell.SHGetDesktopFolder().ParseDisplayName(0, None, sys.argv[1])[1]
        else:
            # And start browsing at the root of the namespace.
            pidl = []
        eb.BrowseToIDList(pidl, shellcon.SBSP_ABSOLUTE)
        # and for some reason the "Folder" view in the navigator pane doesn't
        # magically synchronize itself - so let's do that ourself.
        # Get the tree control.
        sp = eb.QueryInterface(pythoncom.IID_IServiceProvider)
        try:
            tree = sp.QueryService(shell.IID_INameSpaceTreeControl,
                                   shell.IID_INameSpaceTreeControl)
        except pythoncom.com_error as exc:
            # this should really only fail if no "nav" frame exists...
            print("Strange - failed to get the tree control even though " \
                  "we asked for a EBO_SHOWFRAMES")
            print(exc)
        else:
            # get the IShellItem for the selection.
            si = shell.SHCreateItemFromIDList(pidl, shell.IID_IShellItem)
            # set it to selected.
            tree.SetItemState(si, shellcon.NSTCIS_SELECTED, shellcon.NSTCIS_SELECTED)

        #eb.FillFromObject(None, shellcon.EBF_NODROPTARGET); 
        #eb.SetEmptyText("No known folders yet...");  
        self.eb = eb
Exemple #10
0
    def test_parsing_name(self):
        sf = shell.SHGetDesktopFolder()
        flags = shellcon.SHCONTF_FOLDERS | shellcon.SHCONTF_NONFOLDERS
        children = sf.EnumObjects(0, flags)
        child_pidl = children.next()
        name = sf.GetDisplayNameOf(child_pidl, shellcon.SHGDN_FORPARSING)

        item = shell.SHCreateItemFromParsingName(name, None, shell.IID_IShellItem)
        # test the name we get from the item is the same as from the folder.
        self.assertEqual(name, item.GetDisplayName(shellcon.SHGDN_FORPARSING))
Exemple #11
0
def property_sets(filepath):
    pidl, flags = shell.SHILCreateFromPath(os.path.abspath(filepath), 0)
    property_set_storage = shell.SHGetDesktopFolder().BindToStorage(pidl, None, pythoncom.IID_IPropertySetStorage)
    for fmtid, clsid, flags, ctime, mtime, atime in property_set_storage:
        yield FORMATS.get(fmtid, unicode(fmtid)), property_dict(property_set_storage, fmtid)
        if fmtid == pythoncom.FMTID_DocSummaryInformation:
            fmtid = pythoncom.FMTID_UserDefinedProperties
            user_defined_properties = property_dict(property_set_storage, fmtid)
            if user_defined_properties:
                yield FORMATS.get(fmtid, unicode(fmtid)), user_defined_properties
Exemple #12
0
def get_computer_shellfolder():
    """
    Return the local computer's shell folder.
    """
    desktop = shell.SHGetDesktopFolder()
    for pidl in desktop.EnumObjects(0, shellcon.SHCONTF_FOLDERS):
        display_name = desktop.GetDisplayNameOf(pidl, shellcon.SHGDN_NORMAL)
        if display_name in ("Computer", "This PC", "Dieser PC"):
            return desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    return None
Exemple #13
0
    def test_create_item_with_parent(self):
        desktop_pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
        desktop_item = shell.SHCreateItemFromIDList(desktop_pidl, shell.IID_IShellItem)

        sf = shell.SHGetDesktopFolder()
        flags = shellcon.SHCONTF_FOLDERS | shellcon.SHCONTF_NONFOLDERS
        children = sf.EnumObjects(0, flags)
        child_pidl = children.next()
        item1 = shell.SHCreateItemWithParent(desktop_pidl, None, child_pidl, shell.IID_IShellItem)
        item2 = shell.SHCreateItemWithParent(None, sf, child_pidl, shell.IID_IShellItem)
        self.assertShellItemsEqual(item1, item2)
Exemple #14
0
def getDefaultDocumentsDirectory():
    if sys.platform == 'win32':
        try:
            from win32com.shell import shell
            df = shell.SHGetDesktopFolder()
            pidl = df.ParseDisplayName(0, None, "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
            return shell.SHGetPathFromIDList(pidl)
        except:
            print "L'extension win32com pour python est recommandée (plateforme windows) !"
            return os.getcwd()
    else:
        return os.getcwd()
Exemple #15
0
def GetFolderAndPIDLForPath(filename):
    desktop = shell.SHGetDesktopFolder()
    info = desktop.ParseDisplayName(0, None, os.path.abspath(filename))
    cchEaten, pidl, attr = info
    # We must walk the ID list, looking for one child at a time.
    folder = desktop
    while len(pidl) > 1:
        this = pidl.pop(0)
        folder = folder.BindToObject([this], None, shell.IID_IShellFolder)
    # We are left with the pidl for the specific item.  Leave it as
    # a list, so it remains a valid PIDL.
    return folder, pidl
Exemple #16
0
def get_recycle_bin():
    """Yield a list of files in the recycle bin"""
    pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
    desktop = shell.SHGetDesktopFolder()
    h = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    for item in h:
        path = h.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING)
        if os.path.isdir(path):
            # Return the contents of a normal directory, but do
            # not recurse Windows symlinks in the Recycle Bin.
            yield from FileUtilities.children_in_directory(path, True)
        yield path
Exemple #17
0
def get_recycle_bin():
    """Yield a list of files in the recycle bin"""
    pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
    desktop = shell.SHGetDesktopFolder()
    h = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    for item in h:
        path = h.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING)
        if os.path.isdir(path):
            for child in FileUtilities.children_in_directory(path, True):
                yield child
            yield path
        else:
            yield path
Exemple #18
0
def get_documents_dir():
    """:returns: the documents dir for the current user"""
    if _system == 'Linux':
        return _get_xdg_dir("XDG_DOCUMENTS_DIR", "~/Documents")
    elif _system == 'Windows':
        from win32com.shell import shell
        MY_DOCUMENTS = "::{450d8fba-ad25-11d0-98a8-0800361b1103}"
        folder = shell.SHGetDesktopFolder()
        pidl = folder.ParseDisplayName(0, None, MY_DOCUMENTS)[1]
        return shell.SHGetPathFromIDList(pidl)
    elif _system == 'Darwin':
        return os.path.join(os.environ['HOME'], 'Documents')
    else:
        raise SystemExit("unknown system: %s" % (_system, ))
Exemple #19
0
 def selectfiles(show):
     folders = defaultdict(list)
     for p in show:
         folders[os.path.dirname(p)].append(os.path.basename(p))
     for path, files in folders.iteritems():
         files = set(os.path.splitext(f)[0] for f in files) | set(files)
         folder = shell.SHILCreateFromPath(path, 0)[0]
         desktop = shell.SHGetDesktopFolder()
         shell_folder = desktop.BindToObject(folder, None, shell.IID_IShellFolder)
         shell.SHOpenFolderAndSelectItems(
             folder,
             [item for item in shell_folder if desktop.GetDisplayNameOf(item, 0) in files],
             0)
     return 0
Exemple #20
0
def get_my_documents():
    """Return the My Docuemnts folder"""

    df = shell.SHGetDesktopFolder()
    pidl = df.ParseDisplayName(0, None,
                               "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
    mydocs = shell.SHGetPathFromIDList(pidl)

    # TODO: may need to handle window-specific encoding here.
    #encoding = locale.getdefaultlocale()[1]
    #if encoding is None:
    #    encoding = "utf-8"

    return mydocs
Exemple #21
0
    def test_parsing_relative(self):
        desktop_pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
        desktop_item = shell.SHCreateItemFromIDList(desktop_pidl, shell.IID_IShellItem)

        sf = shell.SHGetDesktopFolder()
        flags = shellcon.SHCONTF_FOLDERS | shellcon.SHCONTF_NONFOLDERS
        children = sf.EnumObjects(0, flags)
        child_pidl = children.next()
        name_flags = shellcon.SHGDN_FORPARSING | shellcon.SHGDN_INFOLDER
        name = sf.GetDisplayNameOf(child_pidl, name_flags)

        item = shell.SHCreateItemFromRelativeName(desktop_item,  name, None,
                                                  shell.IID_IShellItem)
        # test the name we get from the item is the same as from the folder.
        self.assertEqual(name, item.GetDisplayName(name_flags))
Exemple #22
0
 def testShellFolder(self):
     sf = shell.SHGetDesktopFolder()
     names_1 = []
     for i in sf: # Magically calls EnumObjects
         name = sf.GetDisplayNameOf(i, SHGDN_NORMAL)
         names_1.append(name)
     
     # And get the enumerator manually    
     enum = sf.EnumObjects(0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN)
     names_2 = []
     for i in enum:
         name = sf.GetDisplayNameOf(i, SHGDN_NORMAL)
         names_2.append(name)
     names_1.sort()
     names_2.sort()
     self.assertEqual(names_1, names_2)
Exemple #23
0
def getUserDocumentsPath():
  """
  Find the user's "Documents" directory (OS X), "My Documents" directory
  (Windows), or home directory (Unix).
  """

  # OS X and Windows code from:
  # http://www.blueskyonmars.com/2005/08/05
  # /finding-a-users-my-documents-folder-on-windows/
  # Alternate Windows code from:
  # http://bugs.python.org/issue1763
  if sys.platform.startswith('win'):
    if sys.platform.startswith('win32'):
      # Try the primary method on 32-bit windows
      try:
        from win32com.shell import shell
        alt = False
      except ImportError:
        try:
          import ctypes
          dll = ctypes.windll.shell32
          alt = True
        except:
          raise Exception("Could not find 'My Documents'")
    else:
      # Use the alternate method on 64-bit Windows
      alt = True
    if not alt:
      # Primary method using win32com
      df = shell.SHGetDesktopFolder()
      pidl = df.ParseDisplayName(0, None,
               "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
      path = shell.SHGetPathFromIDList(pidl)
    else:
      # Alternate method using ctypes rather than win32com
      buf = ctypes.create_string_buffer(300)
      dll.SHGetSpecialFolderPathA(None, buf, 0x0005, False)
      path = buf.value
  elif sys.platform.startswith('darwin'):
    from Carbon import Folder, Folders
    folderref = Folder.FSFindFolder(Folders.kUserDomain,
                                    Folders.kDocumentsFolderType,
                                    False)
    path = folderref.as_pathname()
  else:
    path = os.getenv('HOME')
  return path
Exemple #24
0
def openDirDialog(path=""):
    wnd = win32gui.FindWindow(None, u"文档转转工具")
    # print wnd
    if not path:
        path = ""
    if not os.path.exists(path):
        pidl = shell.SHBrowseForFolder(wnd, None, "Plese select Path")[0]

    else:
        desktop = shell.SHGetDesktopFolder()
        cb, pidl, extra = desktop.ParseDisplayName(0, None, path)
        pidl = shell.SHBrowseForFolder(wnd, None, "Plese select Path")[0]
    try:
        selectPath = shell.SHGetPathFromIDList(pidl)
    except:
        selectPath = path

    saveConf({"reportPath": selectPath.decode('gbk')})
    return selectPath
Exemple #25
0
def get_my_documents():
    """Return the My Documents folder"""
    # See:
    # http://msdn.microsoft.com/en-us/library/windows/desktop/bb776887%28v=vs.85%29.aspx#mydocs  # nopep8
    # http://msdn.microsoft.com/en-us/library/bb762494%28v=vs.85%29.aspx#csidl_personal  # nopep8

    try:
        df = shell.SHGetDesktopFolder()
        pidl = df.ParseDisplayName(
            0, None, "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
    except pywintypes.com_error, e:
        if e.hresult == winerror.E_INVALIDARG:
            # This error occurs when the My Documents virtual folder
            # is not available below the Desktop virtual folder in the
            # file system.  This may be the case if it has been made
            # unavailable using a Group Policy setting.  See
            # http://technet.microsoft.com/en-us/library/cc978354.aspx.
            pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_PERSONAL)
        else:
            raise
Exemple #26
0
    def csv_recycle_bin(self):
        ''' Exports the filenames contained in the recycle bin '''
        with open(
                self.output_dir + '\\' + self.computer_name +
                '_recycle_bin.csv', 'wb') as output:
            csv_writer = get_csv_writer(output)
            #output.write('"Computer Name"|"Type"|"Name 1"|"Name 2"\n')
            idl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
            desktop = shell.SHGetDesktopFolder()
            files = desktop.BindToObject(idl, None, shell.IID_IShellFolder)

            for bin_file in files:
                write_to_csv([
                    self.computer_name, 'Recycle Bin',
                    files.GetDisplayNameOf(bin_file, shellcon.SHGDN_NORMAL),
                    files.GetDisplayNameOf(bin_file, shellcon.SHGDN_FORPARSING)
                ], csv_writer)
        record_sha256_logs(
            self.output_dir + '\\' + self.computer_name + '_recycle_bin.csv',
            self.output_dir + '\\' + self.computer_name + '_sha256.log')
Exemple #27
0
    def csv_recycle_bin(self):
        """Exports the filenames contained in the recycle bin"""
        with open(
                self.output_dir + '\\' + self.computer_name +
                '_recycle_bin.csv', 'wb') as output:
            csv_writer = get_csv_writer(output)
            write_to_csv(("COMPUTER_NAME", "TYPE", "NAME_1", "NAME_2"),
                         csv_writer)
            idl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
            desktop = shell.SHGetDesktopFolder()
            files = desktop.BindToObject(idl, None, shell.IID_IShellFolder)

            for bin_file in files:
                write_to_csv([
                    self.computer_name, 'recycle_bin',
                    files.GetDisplayNameOf(bin_file, shellcon.SHGDN_NORMAL),
                    files.GetDisplayNameOf(bin_file, shellcon.SHGDN_FORPARSING)
                ], csv_writer)
        record_sha256_logs(
            self.output_dir + '\\' + self.computer_name + '_recycle_bin.csv',
            self.output_dir + '\\' + self.computer_name + '_sha256.log')
Exemple #28
0
    def __init__(self):
        '''Initiates VFS.'''
        self.accept("requestMaps", self.sendMaps)
        self.accept("mapRequest", self.generateRegion)

        # Checks to see if home directory is set up properly and does so
        self.home = ""
        if os.name == "nt":
            from win32com.shell import shell
            df = shell.SHGetDesktopFolder()
            pidl = df.ParseDisplayName(
                0, None, "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
            self.home = shell.SHGetPathFromIDList(pidl)
        else:
            self.home = os.path.expanduser("~")
        if "CityMania" not in os.listdir(self.home):
            os.makedirs(self.home + "/CityMania/Maps")
            os.makedirs(self.home + "/CityMania/Regions")
            os.makedirs(self.home + "/CityMania/Logs")
        self.path = self.home + '/CityMania/'
        self.logs = self.path + 'Logs/'
def get_mydocuments_dir():

    if sys.platform in ['darwin', 'mac']:
        from Carbon import Folder, Folders
        folderref = Folder.FSFindFolder(Folders.kUserDomain,
                                        Folders.kDocumentsFolderType, False)
        mydocs = folderref.as_pathname()

    elif 'win' in sys.platform:
        from win32com.shell import shell
        df = shell.SHGetDesktopFolder()
        pidl = df.ParseDisplayName(
            0, None, "::{450d8fba-ad25-11d0-98a8-0800361b1103}")[1]
        mydocs = shell.SHGetPathFromIDList(pidl)

    elif 'linux' in sys.platform:
        mydocs = '~/Desktop'

    else:
        mydocs = os.path.abspath('.')  #cur dir

    return mydocs
Exemple #30
0
def launch_file_explorer(pathes):
    '''Given a list of Path up one File Explorer window
       per folder with all the child files selected'''

    folders = defaultdict(list)
    for p in pathes:
        folders[str(p.parent)].append(p.name)

    for path, files in folders.items():
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(folder_pidl, None,
                                            shell.IID_IShellFolder)
        name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item)
                                     for item in shell_folder])
        to_show = []
        for file in files:
            if not file in name_to_item_mapping:
                wx.LogMessage('File: "%s" not found in "%s"' % (file, path))
                continue
            to_show.append(name_to_item_mapping[file])
        shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)