CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Location
    Melbourne
    Posts
    27

    Question File move, rename in as few steps as possible

    Hi guys,

    I have a situation where I may need to move files owned by a user.

    For example, user "fred" may own the following files in the "FR" directory:-

    \FR\FRED44-010103-1947.ZIP
    \FR\FRED44-010303-1143.ZIP

    I may need to rename the user fred, which means his files have to be renamed and moved.

    Example. User "FRED44" gets renamed to "SMITH67".

    Therefore the files need to be renamed

    SMITH67-010103-1947.ZIP
    SMITH67-010303-1143.ZIP

    and the files *moved* to the "SM" directory.

    From where I see it, I would need to do this:-

    1. Find all files that match "FRED44"
    2. Copy all files to the "SM" directory
    3. Rename the files "FRED44*.ZIP to "SMITH67*.ZIP"
    4. Delete all the FRED44 files in the FR directory.

    Is there a file management API that can do the above - move and rename - in one operation?

    (No special reason for one operation - just efficiency).

    Would that File API support the use of * as the renaming wildcard? As we know good old DOS supports *.

    "XCOPY FRED44*.ZIP C:\SM\SMITH67*.ZIP"

    Comments/code most welcome.

    Thanks,

    Mark

  2. #2
    Join Date
    Mar 2003
    Location
    Melbourne
    Posts
    27

    It's the little things...

    OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"

    Name Oldname as NewName

    Moves the file and renames it...

    Thanks for reading it though!

    Mark

  3. #3
    Join Date
    May 2003
    Location
    Australia
    Posts
    155
    Hi,

    Havent tested this idea, but what about using some of the DOS commands in a shell statement, like "move" or maybe even "xcopy". They have a bucket load of options and will support wildcards.

    Not sure if they have API equivalents, but havent looked it up either (must be getting lazy, and its only Thursday)!

    Cheers,
    Tinbum747
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

  4. #4
    Join Date
    Mar 2003
    Location
    Melbourne
    Posts
    27
    Hi TinBum,

    I did initially toy with the idea of shelling, but then I'd have to "WaitForCompletion", make sure the DOS box closes, etc.

    The name function works brilliantly!

    I grabbed some code showing how to copy files en-masse from one place to another, added my bits of source filename, destination file name, did some string manipulation, and presto! files are moved, renamed and deleted in one step.

    The specific reason I didn't go with a DOS shell was because this file copy/rename/delete operation was happening on on a remote server. I send it a broadcast message with source file spec, destination file spec, and wait for a completion response. Also, DOS shells tend to not clean up nicely leading to deteriorating available memory. It's also easier to report problems if the file copy doesn't happen correctly! (Phew!)

    Mark

  5. #5
    Join Date
    May 2003
    Location
    Australia
    Posts
    155

    Thumbs up

    Cant argue with that ... I am convinced

    Only limitation with Name command, is that it canny move files from one drive to another ... but doesnt seem like that limitation will be a problem with your scenario.

    Cheers
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured