Jump to content

Filecopy, Filemove, Filedelete & Shfileoperation


Jon
 Share

Recommended Posts

  • Administrators

OK, I'm sick of these functions now. Everyone has a different take on if they work or not. And a lot of that code is getting pretty cryptic too. So it's total rewrite time.

To reduce the number of flags required and to mirror the VBScript-ish methods the commands to be split like this:

FileCopy

FileDelete

FileMove

DirCopy

DirMove

DirRemove

Methods of doing:

1. SHFileOperation - this is by far the easiest and after looking at VBScript it is the underlying method used there. It just takes a few lines to perform a DirCopy...

The odd thing about these operations is that you can only have wildcards in the source path. Which is odd and a little annoying.

2. Custom wildcards and directory parsing like the current. Lots of code. Tends to have lots of "weirdness" like the current.

Plus point for number 2 is that there can be limited wildcards in the dest.

Link to comment
Share on other sites

Tough call. I've done a lot of rename programs and copy/move programs, and it does take a lot of code to handle all the exceptions (root directories, target is a folder not a wildcard pattern, source file is overwriting a target directory, etc.)

I didn't even know about SHFileOperation, it sounds interesting.

I never saw much use for having wildcards in the destination parameter (other than to rename files, of course). Coming from both a Unix and Windows background, to me that seems a little atypical. Instead, I'm used to destinations being pure directories or drives.

Perhaps FileRename should be made a separate command from FileMove. That might simplify things: Use SHFileOperation for FileMove and do some custom (but simple) code for FileRename.

Link to comment
Share on other sites

You mean I can have a Deltree like command?  Yay!  Thanks Jon, that will make my TempCleaner (Temperary Files Cleaner) program work much better with less code.  :whistle:

That's what DirRemove("Path", 1) is supposed to do, ever since I wrote it B) , around version 3.0.60, I think. The 1 as a second argument to the function says to recurse to all appropriate subdirectories.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

I don't know what will the final functions and perhaps the exact limit of the today ones.

Basically I want to use

- wildcards

- dir in files meaning dir\*.*

- manage the overidding, already is different from success

- recurse on subdir

- to renaming instead of copying when possible

I try to do it int the dbg-bastard stuff and that what I did

DirCreate("path")

change in return

-1 already

1 a file of same name

2 invalid name

FileCopy("source", "dest" [,flag] )

- allow "source" and "dest" to be dir's equivalent to source\*.*, dest\*.*

- source\<wildcard> dest equivalent to dest\*.*

- source\*.xxx dest\*.yyy

FileDelete("source")

- allow "source to be a dir equivalent to source\*.*

FileMove("source", "dest" [,flag] )

- Flag added to overwrite or not as in FileCopy

- allow "source" and "dest" to be dir's (can be different drives)

. if overwrite is used the subdir's will be moved to

in fact no copy is done under WIN32_NT OsType

if "source" and "dest" are on the same drive just a rename

- same wilcard handling as in FileCopy

Link to comment
Share on other sites

  • Administrators

Tough call.  I've done a lot of rename programs and copy/move programs, and it does take a lot of code to handle all the exceptions (root directories, target is a folder not a wildcard pattern, source file is overwriting a target directory, etc.)

I didn't even know about SHFileOperation, it sounds interesting.

I never saw much use for having wildcards in the destination parameter (other than to rename files, of course).  Coming from both a Unix and Windows background, to me that seems a little atypical.  Instead, I'm used to destinations being pure directories or drives.

Perhaps FileRename should be made a separate command from FileMove.  That might simplify things: Use SHFileOperation for FileMove and do some custom (but simple) code for FileRename.

I didn't know about SHFileOperation either until I looked more closely at the FileRecycle code.

Problem is I quite often do things like copy *.au3 *.au3.bak (same with move). And if you look through some VBScript posts there is always someone bitching about the lack of wildcards.. :whistle:

I may use SHFile to do a CopyDir/MoveDir (with all the recursion nonsense) and then a combined custom routine for FileCopy/FileMove that supports simple wildcards but no recursion. That might work.

Link to comment
Share on other sites

That's what DirRemove("Path", 1) is supposed to do, ever since I wrote it  , around version 3.0.60, I think. The 1 as a second argument to the function says to recurse to all appropriate subdirectories

Yeah, but how can I remove directories I don't know the names in advance without killing the container itself? jlandes mentioned the TEMP-dir which is the best example:

DirRemove("c:\temp", 1) deletes the TEMP directory, too. I could recreate it afterwards but letting the system point to a temp-dir that not exists (even for a second) makes me nervous. :whistle:

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...