Что нового

Копирование файлов с помощью ActiveX

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5,379
Репутация
2,724
Простое копирование файла(ов) с помощью ActiveX (изучаем это).


Код:
; Windows - Copy with progress
; Author - JdeB

;~ 4 Do not display a progress dialog box.
;~ 8 Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
;~ 16 Respond with 'Yes to All' for any dialog box that is displayed.
;~ 64 Preserve undo information, if possible.
;~ 128 Perform the operation on files only if a wildcard file name (*.*) is specified.
;~ 256 Display a progress dialog box but do not show the file names.
;~ 512 Do not confirm the creation of a new directory if the operation requires one to be created.
;~ 1024 Do not display a user interface if an error occurs.
;~ 2048 Version 4.71. Do not copy the security attributes of the file.
;~ 4096 Only operate in the local directory. Don't operate recursively into subdirectories.
;~ 8192 Version 5.0. Do not copy connected files as a group. Only copy the specified files.

_FileCopy('D:\test.tmp', 'C:\')

Func _FileCopy($sFileFrom, $sFileTo)

	Local Const $FOF_RESPOND_YES = 16
	Local Const $FOF_SIMPLEPROGRESS = 256

	$oShell = ObjCreate('Shell.Application')
	$oShell.NameSpace($sFileTo).CopyHere($sFileFrom, $FOF_RESPOND_YES)
EndFunc   ;==>_FileCopy
 

Belfigor

Модератор
Локальный модератор
Сообщения
3,608
Репутация
941
Разве эта тема не должна находиться в разделе посвященном ActiveX?
 

Medic84

Омега
Команда форума
Администратор
Сообщения
1,590
Репутация
341
Она подходит и туда и сюда. Но здесь всего лишь кусок кода(причем очень маленький) который может быть использован где угодно.
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
хотел создать новую тему, но раз есть эта, смысла не вижу.
нового ничего не напишу. но все ж. для общего развития . примеры написаны мною. информацию брал здесь http://www.script-coding.com/WSH/Shell.html#3.18.

пример 1 - копирование файла
Код:
$file = FileOpenDialog('','','(*.*)')
$dir = FileSelectFolder('','')
 $objShellApp = ObjCreate("Shell.Application")
 $objFolder = $objShellApp.NameSpace($dir)
$objFolder.CopyHere($file)


пример 2 - копирование папки
Код:
$dir_s= FileSelectFolder('','')
$dir_d = FileSelectFolder('','')
 $objShellApp = ObjCreate("Shell.Application")
 $objFolder = $objShellApp.NameSpace($dir_d)
$objFolder.CopyHere($dir_s)


копирование нескольких файлов
Код:
$var = FileOpenDialog('', '', '(*.*)', 1 + 4)
$folder = FileSelectFolder('', '',1+2+4)

$var_string = StringReplace($var, "|", '\', 1)
$path = _PathSplitByRegExp($var_string)
$replace = StringReplace($var_string, '|', ',' & $path[2] & '\')
$result = StringSplit($replace, ',')

$objShellApp = ObjCreate("Shell.Application")
$objFolder = $objShellApp.NameSpace($folder)

For $i = 1 To UBound($result) - 1
	$objFolder.CopyHere($result[$i])
Next

;_PathSplitByRegExp
; Author.........:  Gibbo, Mod. by G.Sandler a.k.a (Mr)CreatoR.
Func _PathSplitByRegExp($sPath)
	If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1)

	Local $aRetArray[8], $pDelim = ""

	If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\"
	If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//"

	If $pDelim = "" Then $pDelim = "/"
	If Not StringInStr($sPath, $pDelim) Then Return $sPath
	If $pDelim = "\" Then $pDelim &= "\"

	$aRetArray[0] = $sPath ;Full path
	$aRetArray[1] = StringRegExpReplace($sPath, $pDelim & '.*', $pDelim) ;Drive letter
	$aRetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '') ;Path without FileName and extension
	$aRetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '') ;Full path without File Extension
	$aRetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & ')', '') ;Full path without drive letter
	$aRetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '') ;FileName and extension
	$aRetArray[6] = StringRegExpReplace($sPath, '.*' & $pDelim & '|\.[^.]*$', '') ;Just Filename
	$aRetArray[7] = StringRegExpReplace($sPath, '^.*\.', '') ;Just Extension of a file

	Return $aRetArray
EndFunc   ;==>_PathSplitByRegExp
 
Верх