Occasionally a need arises to move things between computers. You might, for example, be getting about 20 gigabytes of data per week, use it to re-run your model so your parameter estimates stay up to date, and then you must make room for next week's batch.

For this sort of job you probably have a remote RAID system where data is compressed automatically as it arrives. But you need to get it there somehow, and there is an easy way to do so from within the very Stata do-file where your model runs. Here's one way:

// i have three sub-folders and two loose files in the folder "experiment"
// i'm going to xcopy the whole thing to the archive, then rmdir it
local data_from "D:\data\\"
local data_to "\\nairobi\archive\\"
local data_folder1 experiment

// assemble `from_here', `to_here' file paths
foreach where in from to {
  local `where'_here "`data_`where''`data_folder1'"
  di "path `where': ``where'_here'" // this is just for checking
}
// now move stuff
!xcopy "`from_here'" "`to_here'" /e /y /i
!rmdir "`from_here'" /s /q

// notes on command-line options:
// xcopy /e -- copy all sub-directories, including empty ones
// xcopy /i -- copy to a folder that does not yet exist
// xcopy /y -- overwrite existing files at destination without prompting (!)
// rmdir /s -- forced delete of non-empty directory, ask for confirmation first
// rmdir /s /q -- forced delete of non-empty directory, ask no questions (!)

Some details: from a Windows client I am moving data to a Samba server named Nairobi. The Windows shell command "move" works for loose files but not for entire folder structures. Those need to be copied with "xcopy" to the destination computer and then deleted with "rmdir" from the source computer. Both of these commands have some options, as detailed above. I googled a bit, found them here, and figured I'd jot them down inside the Stata do-file for future reference.

There you have it. You can embed this into a loop, say, if you have more than one folder to move, maybe spread across more than one `data_from' file path.