Beispiel #1
0
    def test_rename_with_rename(self):
        from_filepath, to_filepath = self.tempfiles(create_from=True, create_to=True, to_temppath=self.from_temppath)
        f = open(from_filepath, "rb")
        try:
            from_contents = f.read()
        finally:
            f.close()
        winshell.move_file(from_filepath, to_filepath, rename_on_collision=True)

        for filename in set(os.listdir(os.path.dirname(to_filepath))) - set([os.path.basename(to_filepath)]):
            copy_of_filepath = os.path.join(os.path.dirname(to_filepath), filename)
            break

        self.assertFalse(os.path.exists(from_filepath))
        self.assertTrue(os.path.exists(to_filepath))
        f = open(to_filepath, "rb")
        try:
            self.assertNotEqual(from_contents, f.read())
        finally:
            f.close()
        self.assertTrue(os.path.exists(copy_of_filepath))
        f = open(copy_of_filepath, "rb")
        try:
            self.assertEqual(from_contents, f.read())
        finally:
            f.close()
Beispiel #2
0
def generate_shortcut(name, path=None):
    if path is None:
        path = '{0}.bat'.format(name)
    winshell.CreateShortcut(Path=os.path.join(os.path.abspath(os.curdir), '{0}.lnk'.format(name)),
                            Target=path,
                            Icon=(os.path.join(os.path.abspath(os.curdir), '{0}.ico'.format(name)), 0))
    winshell.move_file(source_path='{0}.lnk'.format(name),
                       target_path=os.path.join(winshell.programs(), '{0}.lnk'.format(name)))
Beispiel #3
0
 def test_simple_move(self):
     from_filepath, to_filepath = self.tempfiles(create_from=True, create_to=False)
     f = open(from_filepath, "rb")
     try:
         from_contents = f.read()
     finally:
         f.close()
     winshell.move_file(from_filepath, to_filepath)
     self.assertFalse(os.path.exists(from_filepath))
     self.assertTrue(os.path.exists(to_filepath))
     f = open(to_filepath, "rb")
     try:
         self.assertEqual(from_contents, f.read())
     finally:
         f.close()
Beispiel #4
0
def move(sourcePath, targetPath):
    winshell.move_file(sourcePath, targetPath, no_confirm=True)