[AccessD] Move Folder

Jurgen Welz jwelz at hotmail.com
Mon Apr 26 19:35:25 CDT 2010


>From the debug Immediate window, I typed Filecopy, clicked in the word and hit F1.  From there click the link to 'See Also' and click the "Name Statement" in the Visual Basic Reference.

 

Name Statement:

 

Renames a disk file, directory, or folder.
Syntax

 

Name oldpathname As newpathname
The Name statement syntax has these parts:
 
oldpathname: Required. String expression that specifies the existing file name and location — may include directory or folder, and drive. 

newpathname: Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.
 
Remarks

The Name statement renames a file and moves it to a different directory or folder, if necessary. Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder.
Using Name on an open file produces an error. You must close an open file before renaming it. Name arguments cannot include multiple-character (*) and single-character (?) wildcards.

You can use Robocoy provided you get the quotemarks correct.  That's why I gave you an example.  I use a ShellWait API call so that it proceeds synchronously.  The code doesn't continue until the copy is complete.  I prefer the Robocopy myself, but Name works fine in most instances.  The remarks seem to indicate that Name won't do exactly what I said it does, but, I tested it before the previous posting and it works on our Windows Server system with the VBA that comes with Access 2003 just fine.
 
The quick way to test it is to just try it from the immediate window.  I'd test for existing initial folder, non existent target folder and success result with Dir before your msgbox.
 
Ciao Jürgen Welz 
Edmonton, Alberta 
jwelz at hotmail.com


 > From: rockysmolin at bchacc.com
> To: accessd at databaseadvisors.com
> Date: Mon, 26 Apr 2010 17:10:29 -0700
> Subject: Re: [AccessD] Move Folder
> 
> Name "Z:\Launch\Test" as "S:\dash\Taste"
> 
> That looks like the most efficient way. He wants a module that accepts the
> source folder and target paths. So using your example I would call my
> module MoveIt("Z:\Launch\Test", "S:\dash\Taste") which would have just this:
> 
> Public Sub MoveIt(argSource, argTarget)
> 
> Name argSource & " as " & argTarget
> MsgBox "Folder Moved"
> 
> End sub
> 
> But is Name a key word that does this moving? I've never seen it in VBA
> like that.
> 
> TIA
> 
> Rocky
> 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jurgen Welz
> Sent: Monday, April 26, 2010 4:38 PM
> To: accessd at databaseadvisors.com
> Subject: Re: [AccessD] Move Folder
> 
> 
> You can run Robocopy from an Access form:
> 
> 
> 
> ShellWait "Robocopy.exe """ & strSourcePath & """
> \\Gracsrv\GOMFiles\Estimates\" & r(1) & _ " /E /V
> /log+:\\Gracsrv\GOMFiles\Robocopy.log"
> 
> The above was part of a data migration routine I wrote a while back. There
> was a discussion about ShellWait a couple or 3 months back. In the
> excerpted line above, r(1) was the 2nd field in a recordset that was being
> iterated as strSourcePath was changed in the code loop as well. The
> optional switches for Robocopy are numerous and in this case include
> appending the results in a log file.
> 
> 
> 
> There are recursive folder move routines that work as well and I've written
> more than a fiew based on the Access Developer Handbook, but there is
> another quite easy approach:
> 
> 
> 
> Name "Z:\Launch\Test" as "S:\dash\Taste"
> 
> 
> 
> will move all the files below the folder named Test. I use this to move
> files a fair bit. It moves the files and sub folders nicely. It will not
> create the dash folder but it will create the Taste folder and move
> everything that was in Test to the new Taste folder so you may need to
> create the path with MkDir building out from the root, but once you've got
> the base path, it creates all the sub folders.
> 
> 
> 
> 
> Ciao Jürgen Welz
> 
> Edmonton, Alberta
> 
> jwelz at hotmail.com
> 
> 
> > From: rockysmolin at bchacc.com
> > To: accessd at databaseadvisors.com
> > Date: Mon, 26 Apr 2010 16:16:15 -0700
> > Subject: Re: [AccessD] Move Folder
> > 
> > That looks like it'll do the job - unless he wants it in an Access 
> > form prompting for source and target locations.
> > 
> > Rocky
> > 
> > 
> > -----Original Message-----
> > Sent: Monday, April 26, 2010 3:48 PM
> > Subject: Re: [AccessD] Move Folder
> > 
> > Robocopy..... command line utility.
> > 
> > Drew
> > 
> > -----Original Message-----
> > 
> > Dear List:
> > 
> > What is the best way (through code, of course) to move a folder and 
> > all of its subfolders and files to a new location?
> > 
> > 
> > 
> > MTIA
> > 
> > 
> > 
> > Rocky Smolin
> > 
> 
> 
> _________________________________________________________________
> Videos that have everyone talking! Now also in HD!
> http://go.microsoft.com/?linkid=9724465
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
 		 	   		  
_________________________________________________________________
Got a phone? Get Hotmail & Messenger for mobile!
http://go.microsoft.com/?linkid=9724464


More information about the AccessD mailing list