Results 1 to 11 of 11

Thread: grab a file and put it in anoter

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586

    grab a file and put it in anoter

    Greetings,

    In my program, I extract a text file; and then after extraction, I rename the .txt file as a .~xt file, so that it will not be imported again.

    So, what would be a way to take the backupfile (i.e. the ".~xt" file and put it in a different folder. Say I want the ".~xt" file to go in a folder called "C:\backupFiles" ?

    Right now I have this code below, which simply renames the file, but keeps the file in its present directory.

    bakfile = Mid(pathfile(i), 1, (Len(pathfile(i)) - 4)) & "bak" & nNow & ".~xt" 'formerly "~sv", changed to "~xt" by jrm 3/22/04

    My goal is to send it to a backup directory. What do I need to do?

    One other note, I do not want to keep a copy of the backup in the present directory; I just want to have it in "C:\backupFiles".

    Thank you,
    Jim

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    To keep your current code, FileCopy statement and Kill statement.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Originally posted by leinad31
    To keep your current code, FileCopy statement and Kill statement.
    Sounds like a good plan, and I'm trying to implement it; but for the FileCopy line, below, I keep getting the error:

    "Compile Error: Expected function or variable."

    Any ideas? The code is below.

    Thank you,
    Jim

    bakfile = Mid(pathfile(i), 1, (Len(pathfile(i)) - 4)) & "bak" & nNow & ".~xt" 'formerly "~sv", changed to "~xt" by jrm 3/22/04
    Name pathfile(i) As bakfile 'change the name of pathfile(i) to bakfile
    backupDirectory = "C:/AdcoleTextFileBackups"
    pf = pathfile(i)
    bakfile = FileCopy(pf, backupDirectory)
    Kill pathfile(i)

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    FileCopy doesnt return anything

    VB Code:
    1. FileCopy pf, backupDirectory

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    OK, we're on track with FileCopy.

    One thing I need my code to do though is to create the destination folder before the FileCopy command is used.

    What is the vb code for creating a folder? Say I want to create a folder called "C:\backupFiles".

    How would I code that? The pseudocode being

    create the folder called "C:\backupFiles"

    Thank you,
    Jim

  6. #6
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    You can also use FSO to MoveFile or CopyFile as well.

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    MkDir

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Originally posted by BrianS
    You can also use FSO to MoveFile or CopyFile as well.
    What's FSO?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2002
    Posts
    586
    Originally posted by leinad31
    MkDir
    OK, then how do I first say "if directory does not presently exist"?

    If "C:\backupFiles" does not exist then
    MkDir "C:\backupFiles"
    End If

  10. #10
    Hyperactive Member
    Join Date
    Mar 2003
    Location
    Greece, Salonica
    Posts
    473
    You can use Dir if I remember correcly...
    VB Code:
    1. If Dir(FileName) = "" or filename = "" then
    2. msgbox "Directory not found!", "Error!" , vbexlamection
    3. mkdir "c:\Backup"
    4. end if
    Something like that...

  11. #11
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    If you have MSDN, look at the MoveFile and/or CopyFile commands for FSO (File System Object). I believe that either command will create the destination path if it doesnt exist, but I can't be 100% on that.

    Originally posted by JimMuglia
    What's FSO?

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