-
June 11th, 2003, 11:08 PM
#1
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
-
June 11th, 2003, 11:27 PM
#2
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
-
June 11th, 2003, 11:53 PM
#3
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?
-
June 12th, 2003, 12:48 AM
#4
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
-
June 12th, 2003, 02:19 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|