Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

VB- Saving to a new folder


  • Please log in to reply

#1
ChrisWright

ChrisWright

    Member

  • Member
  • PipPip
  • 34 posts
Due to a set of rather annoying bugs in a game I enjoy playing (Namely 'Uplink'), I decided that I would wish to try and create a program that can copy the save file, and place it in a 'Backup' folder, retaining the original file name.

So far, the program that I have created can copy the the save file to either 'Slot 1' or 'Slot 2', which refers to two folders called '1' and '2' in the backup folder

e.g.

.../Saves/Backup/1
and
.../Saves/Backup/2

Currentely it is also set to overwrite any other file there.

The problem I am facing is that for this program to work, you must create the folders manually, or it will not work. Similarly, if you do not create the folders, there is no indication that the copy has not worked.


The source code for the copying function is as follows (taken from a code website):

Public Function APIFileCopy(src As String, dest As String, _
Optional FailIfDestExists As Boolean) As Boolean

'PURPOSE: COPY FILES
'PARAMETERS: src: Source File (FullPath)
'dest: Destination File (FullPath)
'FailIfDestExists (Optional):
'Set to true if you don't want to
'overwrite the destination file if
'it exists

'Returns (True if Successful, false otherwise)

'EXAMPLE:
'dim bSuccess as boolean
'bSuccess = APIFileCopy ("C:\MyFile.txt", "D:\MyFile.txt")

Dim lRet As Long
lRet = CopyFile(src, dest, FailIfDestExists)
APIFileCopy = (lRet > 0)

End Function

Is anyone able to help me understand how to make it check to see if the folder in the path already exists, and if not, create a new folder?

Thank you for any help!
Chris
  • 0

Advertisements


#2
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
You can call to the FSO (FileSystemObject).
Are you using it for VB6 or VBS?

***EDIT
For VBS I can get you example code of how to create a folder and check if the folder + contents excist.

Edited by IO-error, 12 March 2007 - 02:38 AM.

  • 0

#3
ChrisWright

ChrisWright

    Member

  • Topic Starter
  • Member
  • PipPip
  • 34 posts
I am using VB 6.0, and please would you explain using an example? I am pretty poor at understanding calling the functions and things (e.g. API etc..), and need to get a better grasp of it.

Thanks,
Chris
  • 0

#4
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
I'm sorry, I hope you don't mind, but I can only give VBS examples.
I never used VB6 before, only saw some code.

Give me a few minutes of making an example.
  • 0

#5
IO-error

IO-error

    Member

  • Member
  • PipPipPip
  • 276 posts
Set FSO = CreateObject("Scripting.FileSystemObject")

	FSO.createfolder("FolderName")

		a = 1

	FSO.createfolder "Folder2"

		a= 2

msgbox("Created "&a &" folders")



Set test = fso.GetFolder("FolderName")

	msgbox("FolderName is selected")

test.move("Folder")

	msgbox("FolderName is renamed to Folder")



Set test2 = fso.GetFile("File.txt")

	msgbox("File is created and selected")



test2.Move "C:/folder2/File.txt"

	msgbox("File is moved")



Set test3 = fso.GetFolder("Folder2")

	msgbox("Folder2 is selected")

test3.delete

	msgbox("Folder2 is deleted")

test.delete

	msgbox("Folder is deleted")

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP