Jump to content

How to modify this code?


Recommended Posts

I found this really nice peice of code from 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. 
;~ 9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files.  

_FileCopy("C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe","C:\temp")

Func _FileCopy($fromFile,$tofile) 
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc

Is there a way to set the options to choose between overwriting the files or not? Also, I want to be able to create the directory if the destination dir does not exist. Anyone know of a way to modify this to work?

Link to comment
Share on other sites

  • Moderators

The regular FileCopy() in the help file with that option doens't benefit you?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

I found this really nice peice of code from 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. 
;~ 9182 Version 5.0. Do not copy connected files as a group. Only copy the specified files.  

_FileCopy("C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe","C:\temp")

Func _FileCopy($fromFile,$tofile) 
    Local $FOF_RESPOND_YES = 16
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc

Is there a way to set the options to choose between overwriting the files or not? Also, I want to be able to create the directory if the destination dir does not exist. Anyone know of a way to modify this to work?

Sure, just remove the ",$FOF_RESPOND_YES" and it will prompt you to overwrite the file.

For the directory creation, just use DirCreate()

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Sure, just remove the ",$FOF_RESPOND_YES" and it will prompt you to overwrite the file.

For the directory creation, just use DirCreate()

:P

Jdeb, what does 32 do? It seems to be the only one missing, or am I opening a can of worms?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

Jdeb, what does 32 do? It seems to be the only one missing, or am I opening a can of worms?

must be some MS secret ... its a cut&paste from http://windowssdk.msdn.microsoft.com/en-us...y/ms723207.aspx

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Where is $FOF_SIMPLEPROGRESS ever used?

It isn't in this example but could be "added" to the CopyHere parameter to show a different progress window:

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES + $FOF_SIMPLEPROGRESS)
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Sure, just remove the ",$FOF_RESPOND_YES" and it will prompt you to overwrite the file.

I want to set this option up as a function paramenter, so by adding RESPOND_YES it WILL overwrite the files, but if I just remove it, it prompts for user input. How do I just plainly do something like:

If $overwrite = 1 Then

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

Elseif $overwrite = 0 Then

;dont overwrite the files

Endif

Link to comment
Share on other sites

  • Developers

I want to set this option up as a function paramenter, so by adding RESPOND_YES it WILL overwrite the files, but if I just remove it, it prompts for user input. How do I just plainly do something like:

If $overwrite = 1 Then

$winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)

Elseif $overwrite = 0 Then

;dont overwrite the files

Endif

Use FileExist() to test if it already exists .. :P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

wtf... I didnt do anything different but now this code keeps asking if I want to overwrite files... Its like $FOF_RESPOND_YES = 16 isnt working anymore...

_FileCopy("C:\test_tools\autoItInstall\*.*", "C:\test", 0, 1)

Func _FileCopy($fromFile, $toDir, $overWrite = 0, $createDir = 0)

If $createDir = 1 Then

If DirCreate($toDir) = 0 Then Msgbox(0, "ERROR", $toDir & @LF & "Directory cannot be created.")

EndIf

Local $FOF_RESPOND_YES = 16

Local $FOF_SIMPLEPROGRESS = 256

$winShell = ObjCreate("shell.application")

$winShell.namespace($toDir).CopyHere($fromFile, $FOF_RESPOND_YES)

EndFunc

(C:\test already contains the files from the autoItInstall folder)

Link to comment
Share on other sites

  • Developers

I have the same problem.... none of the options work .

I am prett sure I had that working one time ...

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

bloody hell! thought I found a great solution to all this... *sob* i dont wanna use those long ass progress bar codes that takes up half of my entire program...

As a workaround you could first do a FileDelete() and then the copy bit if you are looking for the progressbar....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

As a workaround you could first do a FileDelete() and then the copy bit if you are looking for the progressbar....

lol then i might need a file delete progress bar! the cycle never ends haha

might just well just stick to the filecopy() in the help file and hope in the next version of autoit the progress bar option can be added

Link to comment
Share on other sites

  • Developers

Ok...according to this page:

http://support.microsoft.com/?kbid=835926

wildcards are not supported for this kind of copy method.

Its still a great method tho, so does anyone know how I can add something to the autoit script that lets me copy the entire contents of one folder into another, and overwrite if neccessary?

Yeap... that's it...

It works fine when a filename is specified.

So just use the FileFindFirstFile() and loop FileFindNextFile() to perform the Func _FileCopy($fromFile,$tofile) for each file in the directory...

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...