Replace your last sub:
sub filelist(grp)
for each file in grp.files
if targ.files.count>=999 then
full=true:exit for
if
lcase(fso.getextensionname(file)) = "eml" then
set objFile =
fso.getfile(file)
arrFileName = Split(objfile.Name,".")
oldname
= arrFileName(0)
ext
= arrFileName(1)
if
fso.FileExists(target & objFile.Name) then
newfile=oldname & cstr(int(Rnd * 1000)) & "." & ext
Else
newfile=objFile.Name
end if
wscript.echo newfile
fso.MoveFile file,target
& newfile
end if
next
End sub
-----------------------------------------------------------------------
Rich Milburn
MCSE, Microsoft MVP -
Directory Services
Sr Network Analyst, Field Platform Development
Applebee's International, Inc.
4551 W. 107th St
Overland Park, KS 66207
913-967-2819
----------------------------------------------------------------------
”I love the smell
of red herrings in the morning” - anonymous
From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tom Kern
Sent: Thursday, December 08, 2005
9:24 AM
To: [email protected]
Subject: Re: [ActiveDir] _vbscript_
help(OT)
I still can't get the rename to work.
the script copies a bunch of eml files from a bunch of source sub
folders. in those sub folders the files have duplicate names but because they
are in sub folders, it doesn't matter until they are being copied to the single
target folder.
So i want to rename the file(keeping the ext) when it encounters the
same file in the target.
Here is what i have so far-
source="c:\fso"
target="c:\tom\"
Set fso =
CreateObject("Scripting.FileSystemObject")
set root=fso.getFolder(source)
set targ=fso.getFolder(target)
dim full
do
if targ.files.count=0 then full=false
if full=false then call folderlist(root)
wscript.sleep 1000
loop
sub
folderlist(grp)
call filelist(grp)
if full then exit sub
for each fldr in grp.subFolders
set nf=fso.GetFolder(fldr.path)
call folderlist(nf)
set nf=nothing
next
end sub
sub
filelist(grp)
for each file in grp.files
if targ.files.count>=999 then full=true:exit for
if lcase(fso.getextensionname(file)) = "eml" then
if targ.FileExists(file) then
file=file + cstr(int(Rnd * 1000))
end if
file.move target
end if
next
End sub
I always
get the error- Object doesn't support this property or
method:'targ.FileExists'
I'm kinda
at a loss here.
thanks
On 12/8/05, Rich
Milburn <[EMAIL PROTECTED]>
wrote:
Tom,
if
lcase(fso.getextensionname(file)) = "eml" then file.move target
-----------------------------------------------------------------------
Rich Milburn
MCSE, Microsoft MVP -
Directory Services
Sr Network Analyst, Field Platform Development
Applebee's International, Inc.
4551 W. 107th St
Overland Park, KS 66207
913-967-2819
----------------------------------------------------------------------
"I love the smell
of red herrings in the morning" - anonymous
isn't
there a way to do it without passing the full path?
i thought
in my statement its implied that whatever "file" should be, it should
look for an .eml ext.
On
12/8/05, Ken Schaefer < [EMAIL PROTECTED]>
wrote:
getExtensionName() requires you to pass it a filespec (a
filename, or path to a file)
If FSO.getExtensionName("c:\windows\clock.avi") =
"avi" Then
' do foo
Else
' do bar
End If
Cheers
Ken
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
On Behalf Of Tom Kern
Sent: Thursday, 8 December 2005
1:48 PM
Oops, I
guess i didn't check my code.
before i
made any changes, i get "Wrong number of arguments or invalid propery
assignment:'fso.getextensionname'.
On
12/7/05, Ken Schaefer < [EMAIL PROTECTED]>
wrote:
At the
moment you have this line which does the copy:
if lcase(fso.getextensionname) = "eml" then file.move target
So, instead of doing the copy, check to see if the file exists at the target,
and if not do the copy. If it does exist, rename the file at the source, then
do the copy.
If LCase(FSO.getExtensionName ) = "eml" Then
If objTarg.FileExists(strSourceFileName)
Then
' Rename Source File
End If
' Now do the copy
End If
Cheers
Ken
________________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
] On Behalf Of Tom Kern
Sent: Thursday, 8 December 2005 12:00 PM
To: [email protected]
Subject: Re: [ActiveDir] _vbscript_ help(OT)
Thanks.
My real problem is, I'm not sure where to put that in my exisiting script
without screwing things up....
Should that be a seperate sub?
Thanks again
On 12/7/05, Brian Desmond < [EMAIL PROTECTED]> wrote:
I don't see the need for a select case, but File.Exists would help.
What I would do is something like this
Dim moveName
moveName = CurrentNameOfFile
While TargetFolder.FileExists (currentNameofFile)
currentNameOfFile = currentNameofFile + Cstr(Int(Rnd * 10000))
Wend
'moveTheFile()
Rnd*1000 will get you some random # 0 - 1000 int makes it an integer and cstr
makes it a string.
Thanks,
Brian Desmond
[EMAIL PROTECTED]
c - 312.731.3132
________________________________________
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
On Behalf Of Tom Kern
Sent: Wednesday, December 07, 2005 7:01 PM
To: activedirectory
Subject: [ActiveDir] _vbscript_ help(OT)
I have this _vbscript_ i wrote/stole tomove all files with an .eml extension
from many subdirs into a folder only if the folder is empty and only to move
999 at a time.
it works great except when it sees files with duplicate names it bombs out
while moving them.
i'd like it to rename the dup(maybe add some random #'s or characters to the
end) and continune movingall thefiles.
I think I have to use "FileExists" method and
"Select...Case" but I'm not
sure how.
Was wondering if anyone could help me with this.
Here is the code-
source="H:\tempxtender"
target="c:\inetpub\mailroot\drop\"
Set fso = CreateObject("Scripting.FileSystemObject")
set root=fso.getFolder(source)
set targ=fso.getFolder(target)
dim full
do
if targ.files.count=0 then full=false
if full=false then call folderlist(root)
wscript.sleep 1000
loop
sub folderlist(grp)
call filelist(grp)
if full then exit sub
for each fldr in grp.subFolders
set nf=fso.GetFolder(fldr.path )
call folderlist(nf)
set nf=nothing
next
end sub
sub filelist(grp)
for each file in grp.files
if targ.files.count>=999 then full=true:exit for
if lcase(fso.getextensionname) = "eml" then file.move target
next
end sub
My aologies for bugging you guys with this OT.
Thanks
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
-------APPLEBEE'S
INTERNATIONAL, INC. CONFIDENTIALITY NOTICE-------
PRIVILEGED /
CONFIDENTIAL INFORMATION may be contained in this message or any attachments.
This information is strictly confidential and may be subject to attorney-client
privilege. This message is intended only for the use of the named addressee. If
you are not the intended recipient of this message, unauthorized forwarding,
printing, copying, distribution, or using such information is strictly
prohibited and may be unlawful. If you have received this in error, you should
kindly notify the sender by reply e-mail and immediately destroy this message.
Unauthorized interception of this e-mail is a violation of federal criminal
law. Applebee's International, Inc. reserves the right to monitor and review
the content of all messages sent to and from this e-mail address. Messages sent
to or from this e-mail address may be stored on the Applebee's International,
Inc. e-mail system.
-------APPLEBEE'S INTERNATIONAL, INC. CONFIDENTIALITY NOTICE-------
PRIVILEGED /
CONFIDENTIAL INFORMATION may be contained in this message or any attachments.
This information is strictly confidential and may be subject to attorney-client
privilege. This message is intended only for the use of the named addressee. If
you are not the intended recipient of this message, unauthorized forwarding,
printing, copying, distribution, or using such information is strictly
prohibited and may be unlawful. If you have received this in error, you should
kindly notify the sender by reply e-mail and immediately destroy this message.
Unauthorized interception of this e-mail is a violation of federal criminal law.
Applebee's International, Inc. reserves the right to monitor and review the
content of all messages sent to and from this e-mail address. Messages sent to
or from this e-mail address may be stored on the Applebee's International, Inc.
e-mail system.
|