Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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