Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to move/rename a file?

Status
Not open for further replies.

FacilitiesCAD

Technical User
Aug 4, 2003
39
US
I have the task of organizing a group of ~1700 autoCAD files. The first step I did was make an access database of all the files and where they are currently stored.
What I want to do is after I've looked at a drawing and determined where it should go is press a button and move that file from its current location to its new location (with a new file name as well)I want the database to store its new location as well.

sub move(original_path,Original_file,new_path,New_file)

anyone done something like this before?

Tim
 
Hi!

I like using the FileSystemObject for these kind of operations. You'll need to check the 'Microsoft Scripting Runtime' library in Tools | References.

To declare and initialize:

dim fs as filesystemobject
set fs=new filesystemobject

Check out the different methods and properties, among the interesting ones, are:

if fs.fileexists ("c:\path\filename.tst") then...
fs.copyfile ("c:\path\source.tst","c:\path\dest_filename.tst", true) ' True=overwrite, false=not (true is default)

finish with

set fs=nothing

There's a move method to, but I like double checking anything, and delete after the copy process;-)

HTH Roy-Vidar
 
I use the following code to copy files to new location and then delete the original. I've cut out most of the code you won't need that was unique to my situation, but you will NEED to modify some of it...hopefully the basic structure will get you going.


Function MoveDocs()
Dim strfilename, strNewFileName As String, i As Integer
Dim strSQL As String
Dim intFlag As Integer
Dim strArchiveDir As String

'Create the name for the document
strNewFileName = leaveID & "~" & doc_type & "~" & Month(Date) & Day(Date) & YEAR(Date) & ".pdf"

strfilename = Forms![switchboard].subformPDFViewer.Form![Pdf9].src

strArchiveDir = (INSERT FILE PATH HERE)

On Error Resume Next
MkDir strArchiveDir 'if already exists the code resumes the next statement
On Error GoTo ErrorHandler

i = 1

While fIsFileDIR(strArchiveDir & strNewFileName) = True

strNewFileName = Mid(strNewFileName, 1, pos) & i
i = i + 1
Wend
strNewFileName = strNewFileName
FileCopy strfilename, strArchiveDir & strNewFileName 'Copy to the archive directory
Kill strfilename 'Kill the original

ExitHere:
Exit Function
ErrorHandler:
MsgBox Err.Number & "-" & Err.Description & ";Please inform contact of problem for review.", vbOKOnly, "ERROR ENCOUNTERED"
Resume ExitHere

End Function
 
Both sound real useful but the second one seems more complicated. Ill try the first one and if I have problems I'll go onto the second. Thanks for the detailled response.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top