Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

file transfer

56 views
Skip to first unread message

Kim Hawker

unread,
Mar 31, 2022, 8:22:57 PM3/31/22
to
How does one transfer a file from folder1 to folder2 in vb6? I’ve tried now for a few days and have not had any success.

Mayayana

unread,
Mar 31, 2022, 9:01:32 PM3/31/22
to
"Kim Hawker" <hawke...@gmail.com> wrote

How does one transfer a file from folder1 to folder2 in vb6? I’ve tried
now for a few days and have not had any success.
>

This is what I use, with lots of error trapping. You can rename
the "js" parts to whatever works for you:

Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA"
(ByVal lpFileName As String) As Long
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName As String, ByVal lpNewFileName As String, ByVal
bFailIfExists As Long) As Long


Public Sub jsMoveFile(fPath As String, fMoveTo As String)
'--move a file. --------------
Dim LRet As Long, LDel As Long, T As Long
Dim iAtr As Integer
On Error Resume Next
Err.Clear
iAtr = GetAttr(fPath)
If Err.Number <> 0 Then Exit Sub

jsDeleteFile fMoveTo

T = 0
SetAttr fPath, 0
LRet = CopyFile(fPath, fMoveTo, ByVal T)
jsDeleteFile fPath

End Sub

Public Sub jsDeleteFile(sDeletePath As String)
'--delete a file. --------------------------
Dim i As Integer
Dim LDel As Long
On Error Resume Next
Err.Clear
i = GetAttr(sDeletePath)
If (Err.Number <> 0) Then Exit Sub
SetAttr sDeletePath, 0
LDel = DeleteFile(sDeletePath)

End Sub


Kim Hawker

unread,
Mar 31, 2022, 10:15:22 PM3/31/22
to
Thank you Mayayana, I now have a lot to study on to learn what is going on. I hope I can learn from this exactly what your doing and why. again thank you.





ObiWan

unread,
Apr 1, 2022, 4:35:39 AM4/1/22
to
:: On Thu, 31 Mar 2022 17:22:56 -0700 (PDT)
:: (microsoft.public.vb.general.discussion)
:: <f3951d28-ac6b-4ab2...@googlegroups.com>
:: Kim Hawker <hawke...@gmail.com> wrote:

> How does one transfer a file from folder1 to folder2 in vb6? I’ve
> tried now for a few days and have not had any success.

Windows offers some "movefile" APIs which aren't difficult to use from
VB, for example

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefile

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-movefileexa

the advantage of using them is that you'll let the system deal with
file integrity and your code will be much more compact; using such APIs
the OS will take care of performing the move operation in a
transactional form so that, in case the operation fails, the original
file won't be damaged; here's an example of using the API

Option Explicit

' movefile flags
Private Const MOVEFILE_REPLACE_EXISTING = &H1
Private Const MOVEFILE_COPY_ALLOWED = &H2
Private Const MOVEFILE_WRITE_THROUGH = &H8

' API
Private Declare Function MoveFileEx Lib "kernel32" _
Alias "MoveFileExA" ( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal dwFlags As Long) As Long

' moves a file to another location, returns 0 if all ok
Public Function vbMoveFile(ByVal sSource As String, _
ByVal sTarget As String) As Long

Dim lRet As Long, lErr As Long
Dim lFlags As Long

' setup the flag
lFlags = MOVEFILE_REPLACE_EXISTING Or _
MOVEFILE_COPY_ALLOWED

' clear the error values
Err.Clear

' perform the move and gets API error if any
lRet = MoveFileEx(sSource, sTarget, lFlags)
lErr = Err.LastDllError

' check operation result
If lRet <> 0 Then
lErr = 0
End If

' all done, 0 if ok
vbMoveFile = lErr
End Function

notice that the same API can also be used to move a whole folder tree
(folder and subfolders) to another location, but in such a case there
are some limitations which should be taken into account, for details,
see the API references above

HTH




John K.Eason

unread,
Apr 1, 2022, 7:29:37 AM4/1/22
to
In article <bebbd3da-5c78-4766...@googlegroups.com>,
hawke...@gmail.com (Kim Hawker) wrote:

> *From:* Kim Hawker <hawke...@gmail.com>
> *Date:* Thu, 31 Mar 2022 19:15:21 -0700 (PDT)
>
> On Thursday, March 31, 2022 at 8:01:32 PM UTC-5, Mayayana wrote:
>
> > This is what I use, with lots of error trapping. You can rename
> > the "js" parts to whatever works for you:
.....
>
> Thank you Mayayana, I now have a lot to study on to learn what is
> going on. I hope I can learn from this exactly what your doing and
> why. again thank you.
>
There's also this: http://vbnet.mvps.org/code/shell/shdirectorycopy.htm which is
pretty comprehensive although it doesn't include error checking.

--
Regards
John (jo...@jeasonNoSpam.cix.co.uk) Remove the obvious to reply...

Mayayana

unread,
Apr 1, 2022, 8:50:36 AM4/1/22
to
"Kim Hawker" <hawke...@gmail.com> wrote

inline...

| > Public Sub jsMoveFile(fPath As String, fMoveTo As String)
| > '--move a file. --------------
| > Dim LRet As Long, LDel As Long, T As Long
| > Dim iAtr As Integer

------don't raise an error if the file does not exist.
| > On Error Resume Next

------ not officially necessary, but I'm a nervous type.
| > Err.Clear

------ check whether the file exists by checking for attributes.
| > iAtr = GetAttr(fPath)
| > If Err.Number <> 0 Then Exit Sub
| >

------ delete the destination file if it already exists.
| > jsDeleteFile fMoveTo
| > T = 0

--------- copy the file via API call supported on all Windows systems.
| > SetAttr fPath, 0
| > LRet = CopyFile(fPath, fMoveTo, ByVal T)

---------- delete the original via API call to DeleteFile, supported
on all Windows systems.

| > jsDeleteFile fPath

---- If you look up MoveFile you'll find that function exists
in the Win32 API, but it's misnamed. It should be RenameFile.
Officially the function will move a file or folder, but the docs
say it will fail if a folder is moved to a different volume. Quirky.

As I recall there are also other reasons to stick with the
method above, but I don't remember them offhand.


ObiWan

unread,
Apr 1, 2022, 9:48:10 AM4/1/22
to
:: On Fri, 1 Apr 2022 08:50:52 -0400
:: (microsoft.public.vb.general.discussion)
:: <t26seq$acf$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> ---- If you look up MoveFile you'll find that function exists
> in the Win32 API, but it's misnamed. It should be RenameFile.

Uh... maybe I misunderstood, but just checked my VB6 API tool and the
"MoveFileEx" is right there

> Officially the function will move a file or folder, but the docs
> say it will fail if a folder is moved to a different volume. Quirky.

That's why I used "MoveFileEx", since by passing it the right flag it
will work across volumes/media and can also overwrite an existing file
(not a folder btw)

ObiWan

unread,
Apr 1, 2022, 9:48:59 AM4/1/22
to
:: On Fri, 1 Apr 2022 15:48:07 +0200
:: (microsoft.public.vb.general.discussion)
:: <20220401154...@mvps.org>
Oh, and the MoveFileEx is supported from, at least, Win2k





ObiWan

unread,
Apr 1, 2022, 11:26:18 AM4/1/22
to
:: On Thu, 31 Mar 2022 17:22:56 -0700 (PDT)
:: (microsoft.public.vb.general.discussion)
:: <f3951d28-ac6b-4ab2...@googlegroups.com>
:: Kim Hawker <hawke...@gmail.com> wrote:

> How does one transfer a file from folder1 to folder2 in vb6? I’ve
> tried now for a few days and have not had any success.

the simplest way, using native VB code, would be the following (notice
that the destination folder should exist)

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-statement

and the resulting code could be something like this

' moves/renames a file, returns true if success
Function MoveFile(ByVal sSrc As String, _
ByVal sDst As String) As Boolean

Dim vAttr As VbFileAttribute
Dim lErr As Long, bRet As Boolean

' initialize
bRet = False

' check if DST exists using getattr
On Error Resume Next
Err.Clear
vAttr = GetAttr(sDst)
lErr = Err.Number

' engage error handler
On Error GoTo Catch

' if DST exist we should delete it
If lErr = 0 Then
SetAttr sDst, vbNormal
Kill sDst
End If

' now move/rename SRC as DST
Name sSrc As sDst

' all ok
bRet = True

BailOut:
' return True if all ok
MoveFile = bRet
Exit Function

Catch:
' error moving the file
bRet = False
Resume BailOut
End Function

Apd

unread,
Apr 1, 2022, 11:34:17 AM4/1/22
to
"ObiWan" wrote:
>:: ObiWan wrote:
>>:: "Mayayana" wrote:
>>> Officially the function will move a file or folder, but the docs
>>> say it will fail if a folder is moved to a different volume. Quirky.
>>
>> That's why I used "MoveFileEx", since by passing it the right flag it
>> will work across volumes/media and can also overwrite an existing file
>> (not a folder btw)
>
> Oh, and the MoveFileEx is supported from, at least, Win2k

All these file operations are supported from NT 3.1. The only reason
I can see to prefer CopyFile/DeleteFile is that MoveFileEx is
unsupported on Win9x/Me.


ObiWan

unread,
Apr 1, 2022, 11:51:25 AM4/1/22
to
:: On Fri, 1 Apr 2022 16:34:04 +0100
:: (microsoft.public.vb.general.discussion)
:: <t2761n$do5$1...@apd.eternal-september.org>
:: "Apd" <n...@all.invalid> wrote:

> The only reason I can see to prefer CopyFile/DeleteFile is that
> MoveFileEx is unsupported on Win9x/Me.

... assuming someone is still developing stuff to support those
platforms, that is :D

Mayayana

unread,
Apr 1, 2022, 12:12:26 PM4/1/22
to
"ObiWan" <obi...@mvps.org> wrote

> The only reason I can see to prefer CopyFile/DeleteFile is that
> MoveFileEx is unsupported on Win9x/Me.

| ... assuming someone is still developing stuff to support those
| platforms, that is :D
|

MoveFileEx:
"When moving a directory, the destination must be on the same drive."

It further states that if a file is moved to another drive,
CopyFileEx will actually use the CopyFile and DeleteFile
methods, as I did.

So the Copy/Delete approach works, MoveFileEx is partially
just a wrapper for it, and it's more widely supported and doesn't
have gotchas. I expect the SHFileOperation method might also
be OK. I haven't tried it.

It's true that there are probably very, very few people
using Win98. On the other hand, someone in E. Europe or
Asia, or in rural US might be, and they might be able to use
my sfoftware. So why break what doesn't need to be broken,
especially with a boobytrapped method?


Mayayana

unread,
Apr 1, 2022, 12:18:29 PM4/1/22
to
"ObiWan" <obi...@mvps.org> wrote

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-statement

Only works with files and can't be used to move across
drives. You should mention these things if you're going to
offer faulty methods. There may have been a time when
moving across drives was rare, but it's very common today
to save to a second hard disk or a USB stick.




Apd

unread,
Apr 1, 2022, 1:28:31 PM4/1/22
to
"ObiWan" wrote:
>:: "Apd" wrote:
>> The only reason I can see to prefer CopyFile/DeleteFile is that
>> MoveFileEx is unsupported on Win9x/Me.
>
> ... assuming someone is still developing stuff to support those
> platforms, that is :D

Well, yes. The thing is, VB can run on 9x and if people are still
using that they might expect any VB program will run on it. It annoys
me when compatibility is broken for no good reason.


Mayayana

unread,
Apr 1, 2022, 2:07:18 PM4/1/22
to
"Apd" <n...@all.invalid> wrote

| Well, yes. The thing is, VB can run on 9x and if people are still
| using that they might expect any VB program will run on it. It annoys
| me when compatibility is broken for no good reason.
|

Indeed. In most cases I don't think that people even
realize. Too many programmers don't know anything about
the systems they target.

Today I was visiting Home Depot.
The pictures don't show. Huh? Irfan View tells me the JPG
file specced in a normal IMG tag is actually a .webp. Firefox
52 on XP doesn't recognize it. A recent version of New Moon
sees it, but seems to only render it if I go the the file URL
itself. Years ago no one would have used a new fomat like
that for years. Today the web designer has no idea how
to code. They just use an automated webpage generator and
add a disclaimer: "Your browser is too old." I see that as a
popup, then the page renders. :)


Apd

unread,
Apr 1, 2022, 7:42:32 PM4/1/22
to
"Mayayana" wrote:
> Today I was visiting Home Depot.
> The pictures don't show. Huh? Irfan View tells me the JPG
> file specced in a normal IMG tag is actually a .webp. Firefox
> 52 on XP doesn't recognize it. A recent version of New Moon
> sees it, but seems to only render it if I go the the file URL
> itself. Years ago no one would have used a new fomat like
> that for years.

Yes, webp appeared in Firefox 65 (Jan 2019).

> Today the web designer has no idea how
> to code. They just use an automated webpage generator and
> add a disclaimer: "Your browser is too old." I see that as a
> popup, then the page renders. :)

Some won't render at all because of script incompatibility and they
don't even tell you. For example, imgur.com started using the
ResizeObserver DOM API in 2020. This had only been introduced for
Firefox 69 in Sep 2019! There's a polyfill (emulation code) available
which is not perfect but they don't bother to use it. Fortunately,
the image which would be displayed can be fished out of the page
source (I know your feelings about sites that depend totally on
script from reading some of the Win groups).


Kim Hawker

unread,
Apr 1, 2022, 8:33:31 PM4/1/22
to
On Thursday, March 31, 2022 at 8:01:32 PM UTC-5, Mayayana wrote:

> This is what I use, with lots of error trapping. You can rename
> the "js" parts to whatever works for you:
>
I can't figure out how to let it know the path to get and/or the path to put.

Mayayana

unread,
Apr 1, 2022, 10:10:50 PM4/1/22
to
"Kim Hawker" <hawke...@gmail.com> wrote
|
| > This is what I use, with lots of error trapping. You can rename
| > the "js" parts to whatever works for you:
| >
| I can't figure out how to let it know the path to get and/or the path to
put.

That's up to you. It's code to move a file, not to figure out
what file to move.

jsMoveFile "C:\folder1\file.txt", "C:\folder2\file.txt"


Kim Hawker

unread,
Apr 1, 2022, 10:37:00 PM4/1/22
to
Thank you, now I understand. Sorry and thank you.

Kim Hawker

unread,
Apr 1, 2022, 11:27:47 PM4/1/22
to
On Friday, April 1, 2022 at 9:10:50 PM UTC-5, Mayayana wrote:

> That's up to you. It's code to move a file, not to figure out
> what file to move.

Now I do have something I can work with. Thanks again Mayayana.

ObiWan

unread,
Apr 4, 2022, 3:41:41 AM4/4/22
to
:: On Fri, 1 Apr 2022 12:12:42 -0400
:: (microsoft.public.vb.general.discussion)
:: <t27897$uhq$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> MoveFileEx:
> "When moving a directory, the destination must be on the same drive."

Yes, but the OP asked to move a file, not a folder

> It further states that if a file is moved to another drive,
> CopyFileEx will actually use the CopyFile and DeleteFile
> methods, as I did.

Yes, but that will be trasparent, if you specify the
"MOVEFILE_COPY_ALLOWED" flag, the MoveFileEx will either use the move,
which will NOT perform a copy/delete of the file but just change the
file system pointer (so the move will be immediate), or, if the source
and destination are on different disks, the movefile will use the copy
and delete; but as I wrote it will be transparent, plus if the move is
on the same disk, the move will be much faster since there won't be a
"copy" of the data

> So the Copy/Delete approach works

Sure, if one does it correctly, that is, one should:

1. Generate a temporary name which does NOT exist in the target path

2. Copy the source file to the destination path using the temporary name

3. If the destination file exist, delete it

4. Rename the temporary file name to the destination name

5. Delete the source file

and, if any of the above steps fail, roll things back so that the
source will be left intact and the destination won't carry traces of
the attempted operation; all the above is automatically handled by the
MoveFileEx, more, the API won't perform the "copy" if the file is on
the same disk, see why I prefer the movefileex now :) ?


ObiWan

unread,
Apr 4, 2022, 3:43:26 AM4/4/22
to
:: On Fri, 1 Apr 2022 12:18:45 -0400
:: (microsoft.public.vb.general.discussion)
:: <t278kj$6di$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> "ObiWan" <obi...@mvps.org> wrote
>
> https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-statement
>
> Only works with files and can't be used to move across
> drives.

Incorrect, if works with files or folders, can move a file across disks
but can't move a folder across disks, just like the MoveFileEx API.

Mayayana

unread,
Apr 4, 2022, 9:10:14 AM4/4/22
to
"ObiWan" <obi...@mvps.org> wrote

Sure, if one does it correctly, that is, one should:

1. Generate a temporary name which does NOT exist in the target path

2. Copy the source file to the destination path using the temporary name

3. If the destination file exist, delete it

4. Rename the temporary file name to the destination name

5. Delete the source file
>

You're so competitive. You'd argue that the sun rises in
the west if it helped to win an argument. You just always
have to be the boss.

In this case, your argument about creating temp files is
simply nonsense. You're writing nonsense in a help forum
just to win an argument, confusing the issue unnecessarily.

Perhaps the worst part is that you value understanding so
little that you'll try to thwart it in others for the sake of
imagined power. Personally I find that very small minded.
There are those who delight in providing knowledge to others.
Then there are those who only compete, with the attitude
of, "That's for me to know and for you to find out." Interestingly,
both types are often attracted to roles in education one for
passion and the other to stifle the competition.


ObiWan

unread,
Apr 4, 2022, 9:17:32 AM4/4/22
to
:: On Mon, 4 Apr 2022 09:10:28 -0400
:: (microsoft.public.vb.general.discussion)
:: <t2eqnj$aqp$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> In this case, your argument about creating temp files is
> simply nonsense. You're writing nonsense in a help forum
> just to win an argument, confusing the issue unnecessarily.

It isn't to "confuse", it's the right way to perform the move operation
and the "temp" file passage has it reason to be, if you fail to see it,
then it isn't a problem for me; and no, there's no "competition" or the
like, what I suggest is just due to my personal experience and need to
solve some possible issues (which I was faced with), then and again, if
you consider this some kind of "competition" or if you fail to see why
someone else is doing things differently from the way you do them, it
isn't a problem for me


Mayayana

unread,
Apr 4, 2022, 9:22:22 AM4/4/22
to
"ObiWan" <obi...@mvps.org> wrote

> Only works with files and can't be used to move across
> drives.

Incorrect, if works with files or folders, can move a file across disks
but can't move a folder across disks, just like the MoveFileEx API.
|

Interesting. Your link does seem to say that. VB and VBA in
a Nutshell clearly states that "newpathname and oldpathname
can't be on different drives". I guess I'd want to test that if
I were thinking of using it. Presumably it at least supports Win9x.
So I guess it's probably a wrapper for MoveFile. And indeed,
MoveFileA is listed in the import table of msvbvm60.dll.


ObiWan

unread,
Apr 4, 2022, 9:27:54 AM4/4/22
to
:: On Mon, 4 Apr 2022 09:22:37 -0400
:: (microsoft.public.vb.general.discussion)
:: <t2ereb$ge5$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> Interesting. Your link does seem to say that. VB and VBA in
> a Nutshell clearly states that "newpathname and oldpathname

from

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-statement

"Name can move a file across drives, but it can only rename an existing
directory or folder when both newpathname and oldpathname are located
on the same drive."

I believe it's pretty clear, isn't it ?

ObiWan

unread,
Apr 4, 2022, 9:28:42 AM4/4/22
to
:: On Mon, 4 Apr 2022 15:27:51 +0200
:: (microsoft.public.vb.general.discussion)
:: <20220404152...@mvps.org>
Oh, and as for the "movefile", it's the very same API which gets
invoked when you issue a "ren" from a command prompt :P

ObiWan

unread,
Apr 4, 2022, 9:30:50 AM4/4/22
to
:: On Mon, 4 Apr 2022 15:28:39 +0200
and the "move" command too, the "ren(ame)" has some limitations which
are "self imposed" to mantain backwards compatibility

Mayayana

unread,
Apr 4, 2022, 12:47:28 PM4/4/22
to
"ObiWan" <obi...@mvps.org> wrote


> Interesting. Your link does seem to say that. VB and VBA in
> a Nutshell clearly states that "newpathname and oldpathname

from

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-statement

"Name can move a file across drives, but it can only rename an existing
directory or folder when both newpathname and oldpathname are located
on the same drive."

I believe it's pretty clear, isn't it ?
>

Yes. That's what I said. Take a breath. Either the
docs or the O'Relliy book are mistaken.


ObiWan

unread,
Apr 5, 2022, 4:13:10 AM4/5/22
to
:: On Mon, 4 Apr 2022 12:47:43 -0400
:: (microsoft.public.vb.general.discussion)
:: <t2f7eu$op7$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> Yes. That's what I said. Take a breath.

Heh... you bet; the last 15 days haven't been exactly a walk in the
park <deep sigh>

> Either the
> docs or the O'Relliy book are mistaken.

well, just tried the following in VB6

Name "c:\temp\test01.txt" As "d:\temp\test02.txt"

and it worked w/o problems, so I can definitely confirm that the VB
native "name" command works across drives (for files), this means that
with a bit of code to handle the deletion of an existing target file,
the native command will allow to perform file moves w/o having to use
API calls


Aoli

unread,
Apr 5, 2022, 12:18:47 PM4/5/22
to
That's why MyPal browser works for me on HomeDepot pages from my Win XP
Pro laptop. Also Amazon videos.
O.T. any opinions on MyPal ?

Mayayana

unread,
Apr 5, 2022, 1:22:15 PM4/5/22
to
"Aoli" <Ao...@Aoli.com> wrote

| That's why MyPal browser works for me on HomeDepot pages from my Win XP
| Pro laptop. Also Amazon videos.
| O.T. any opinions on MyPal ?
|

It seems to be the same rendering engine as
Pale Moon/New Moon, so I wouldn't expect it to be
as good as recent Gecko. Personally I just can't get
past that silly name and icon. Did they think they were
making a browser for 5-year-olds?

I'd like to find out more of the info like what Apd posted.
Though I'm not sure it's feasible anymore to really figur out why
a webpage breaks. Sometimes they want it to break. Other
times it's running on top of gobs of obfuscated and "minified"
javascript. At one time I could figure out code problems.
Today's pages often leave me stumped. Though I did start
keeping a file on my desktop for image sites. Whenever possible,
I try to tell people to use postimg.cc, postimages.org. On
Reddit they seem to favor imgur, and as Apd said, those people
have broken their site. You'd think that maybe they could hanle
writing a webpage with a link to an image on it, but nooooooo. :)


Apd

unread,
Apr 5, 2022, 5:23:06 PM4/5/22
to
"Mayayana" wrote:
> "Aoli" wrote
> | That's why MyPal browser works for me on HomeDepot pages from my Win
> | XP Pro laptop. Also Amazon videos.
> | O.T. any opinions on MyPal ?

I always meant to try it but never got a round tuit. If I absolutely
must get to such a site I use the latest Firefox on my Win7 laptop.

> It seems to be the same rendering engine as
> Pale Moon/New Moon, so I wouldn't expect it to be
> as good as recent Gecko. Personally I just can't get
> past that silly name and icon. Did they think they were
> making a browser for 5-year-olds?

You may or may not be aware of this announcement and the TLDR story
about the spat with Palemoon linked from there:
https://github.com/Feodor2/mypal

> I'd like to find out more of the info like what Apd posted.
> Though I'm not sure it's feasible anymore to really figur out why
> a webpage breaks. Sometimes they want it to break. Other
> times it's running on top of gobs of obfuscated and "minified"
> javascript. At one time I could figure out code problems.
> Today's pages often leave me stumped. Though I did start
> keeping a file on my desktop for image sites. Whenever possible,

Often you can find out, like I did with imgur when it suddenly stopped
working, by looking in the dev console (F12) and reading the error
messages where it'll say "[some DOM object] is not defined". It can
sometimes be really tedious, though.

> I try to tell people to use postimg.cc, postimages.org.

imgbb.com is another one I use. You can have direct links to images.

> On Reddit they seem to favor imgur, and as Apd said, those people
> have broken their site. You'd think that maybe they could hanle
> writing a webpage with a link to an image on it, but nooooooo. :)

It's nuts.


Mayayana

unread,
Apr 5, 2022, 8:06:05 PM4/5/22
to
"Apd" <n...@all.invalid> wrote

| You may or may not be aware of this announcement and the TLDR story
| about the spat with Palemoon linked from there:
| https://github.com/Feodor2/mypal
|

I'm not aware of any of that. You sure do get around.
That developer, whoever he is, looks like someone to watch.

|
| imgbb.com is another one I use. You can have direct links to images.
|

Thanks. I've added that to my list.


ObiWan

unread,
Apr 6, 2022, 3:05:53 AM4/6/22
to
:: On Tue, 5 Apr 2022 20:06:19 -0400
:: (microsoft.public.vb.general.discussion)
:: <t2ilhb$142$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> | You may or may not be aware of this announcement and the TLDR story
> | about the spat with Palemoon linked from there:
> | https://github.com/Feodor2/mypal
> |
>
> I'm not aware of any of that. You sure do get around.
> That developer, whoever he is, looks like someone to watch.

Well, and btw one may also want to stay FAR AWAY from "PaleMoon", the
reasons for this should be pretty clear after reading the following

https://github.com/Feodor2/Mypal/issues/3

then, the decision is up to oneself, by the way.

Mayayana

unread,
Apr 6, 2022, 7:16:28 AM4/6/22
to
"ObiWan" <obi...@mvps.org> wrote

>
> I'm not aware of any of that. You sure do get around.
> That developer, whoever he is, looks like someone to watch.

Well, and btw one may also want to stay FAR AWAY from "PaleMoon", the
reasons for this should be pretty clear after reading the following

https://github.com/Feodor2/Mypal/issues/3

then, the decision is up to oneself, by the way.
|

Maybe you can explain what your point is. I don't understand
what I'm reading on that page. It appears to be an argument
where the MyPal author feels persecuted and others are
telling him it's because he hasn't properly released his source
code.




ObiWan

unread,
Apr 8, 2022, 5:52:59 AM4/8/22
to
:: On Thu, 31 Mar 2022 17:22:56 -0700 (PDT)
:: (microsoft.public.vb.general.discussion)
:: <f3951d28-ac6b-4ab2...@googlegroups.com>
:: Kim Hawker <hawke...@gmail.com> wrote:

> How does one transfer a file from folder1 to folder2 in vb6? I’ve
> tried now for a few days and have not had any success.

Summing up all the stuff discussed, here's a code snippet which allows
to move files to a different folder and optionally rename them, notice
that the code doesn't use APIs and that it tries to leave source and
destination untouched in case of error; to use the code to move a file
just issue something like

sSrcFile = "c:\temp\foobar.txt"
sDstFile = "d:\somedir\readme.txt"
bRet = MoveFile(sSrcFile, sDstFile)
If Not bRet Then
MsgBox "Error:" & Err.Number & " " & Err.Description
' ...handle error condition...
End If

all the above being said, here's the code


Option Explicit

' move a file to a different path and optionally rename it
Public Function MoveFile(ByVal sSrc As String, _
ByVal sDst As String) As Boolean
Dim sPath As String, sTemp As String
Dim bExist As Boolean

' init
On Local Error Resume Next
Err.Clear
MoveFile = False

' setup dst path and temp name
sPath = GetPath(sDst)
sTemp = TempFile(sPath)

' if dst exists rename to temp
If FileExists(sDst) Then
bExist = True
Name sDst As sTemp
If Err.Number <> 0 Then
Exit Function
End If
End If

' move src to dst
Name sSrc As sDst
If Err.Number <> 0 Then
If bExist Then
' restore dst from temp
Name sTemp As sDst
End If
Exit Function
End If

' delete temp (old dst file)
If Not KillFile(sTemp) Then
Exit Function
End If

' all ok
MoveFile = True
End Function

' delete a file
Public Function KillFile(ByVal sPathName As String) As Boolean
Dim bRet As Boolean

' init
On Local Error GoTo Catch
Err.Clear
bRet = False

' set attr to normal and kill the file
SetAttr sPathName, vbNormal
Kill sPathName
bRet = True

BailOut:
KillFile = bRet
Exit Function

Catch:
bRet = False
Resume BailOut
End Function

' generate a temp file name for a given folder
Public Function TempFile(ByVal sPathName As String) As String
Dim sTemp As String
Dim lTemp As Long
Dim bDone As Boolean

bDone = False
Randomize Timer
While Not bDone
lTemp = Int(Rnd * &H7FFFFFFF)
sTemp = sPathName & "~" & Hex(lTemp) & ".tmp"
bDone = IIf(FileExists(sTemp), False, True)
Wend
TempFile = sTemp
End Function

' get the path out of a pathname
Public Function GetPath(ByVal sPathName As String) As String
Dim sPath As String, nPos As Integer

sPath = ".\"
nPos = InStrRev(sPathName, "\")
If nPos < 1 Then
nPos = InStr(sPathName, ":")
End If
If nPos > 0 Then
sPath = Mid(sPathName, 1, nPos)
End If
GetPath = sPath
End Function

' check if a file exists
Public Function FileExists(ByVal sPathName As String) As Boolean
Dim vAttr As VbFileAttribute
Dim bRet As Boolean

On Local Error Resume Next
Err.Clear
vAttr = GetAttr(sPathName)
bRet = IIf(Err.Number = 0, True, False)
Err.Clear
FileExists = bRet
End Function


Mayayana

unread,
Apr 8, 2022, 8:56:04 AM4/8/22
to
"ObiWan" <obi...@mvps.org> wrote

Summing up all the stuff discussed, here's a code snippet which allows
to move files to a different folder and optionally rename them, notice
that the code doesn't use APIs and that it tries to leave source and
destination untouched in case of error; to use the code to move a file
just issue something like
>

I'd say that you're unquestionably the winner of the annual
Rube Goldberg Confuse The Issue prize. You've managed to use
an obscure method repeatedly, sprinkle your disk with
unnecessary temp files, and even make unnecessary variables.
But you've also gone the extra mile, creating no less than 5
functions to move a file! I guess that's why you're the MVP.
With advice like that you'll never have any competition.

I look forward to you next article: "How to Make a Ham and
Cheese Sandwich by Driving to North Dakota". :)




ObiWan

unread,
Apr 8, 2022, 9:19:16 AM4/8/22
to
:: On Fri, 8 Apr 2022 08:56:18 -0400
:: (microsoft.public.vb.general.discussion)
:: <t2pbd2$188$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> I'd say that you're unquestionably the winner of the annual

You seem to be in a pretty harsh mood today :P

Anyhow... if you don't like the code example, just don't use it, you
may just go straight and use a bit of error handling and something like

Kill sDestFile
Name sSourceFile As sDestFile

that's fine with me; but please, make yourself a question; what will
happen if the "Kill" succeeds w/o errors but the "Name" bombs with an
error ?


Mayayana

unread,
Apr 8, 2022, 5:03:16 PM4/8/22
to
"ObiWan" <obi...@mvps.org> wrote

> You seem to be in a pretty harsh mood today :P

You go out of your way to confuse people. I don't
want to see aynyone taken in by your antics.



ObiWan

unread,
Apr 11, 2022, 3:54:57 AM4/11/22
to
:: On Fri, 8 Apr 2022 17:03:29 -0400
:: (microsoft.public.vb.general.discussion)
:: <t2q7uh$tjh$1...@dont-email.me>
:: "Mayayana" <maya...@invalid.nospam> wrote:

> "ObiWan" <obi...@mvps.org> wrote
>
> > You seem to be in a pretty harsh mood today :P
>
> You go out

the fact that you skipped the remainder of my post in your reply is
quite peculiar; thank you for this.


0 new messages