Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - copy and rename into same dir

Reply
 
Old 02-03-2009   #1 (permalink)
rodchar


 
 

copy and rename into same dir

hey all,
is there an easy way to copy each file in my directory and paste into the
same diretory but with a number 1 appended to the filename?

dir1 before
fileA
fileB


dir2 after script
fileA
fileA1
fileB
fileB1

thanks,
rodchar


My System SpecsSystem Spec
Old 02-03-2009   #2 (permalink)
Dirk Stegemann


 
 

Re: copy and rename into same dir

Hi rodchar,

--
Quote:

> is there an easy way to copy each file in my directory and paste into the
> same diretory but with a number 1 appended to the filename?
--

hope this one helps you a little bit...

--Start --

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(".")
ReDim aFile(500)
i = 0
For Each oFile In oFolder.Files
aFile(i) = oFile.Name
i= i+1
Next
ReDim Preserve aFile(i -1)
For i = LBound (aFile) To UBound (aFile)
If aFile(i) <> "" then
sFilename = Left(aFile(i), InStr(aFile(i), ".") -1)
sEndung = Mid(aFile(i), InStr(aFile(i), "."), _
Len(aFile(i))- InStr(aFile(i), ".")+1)
sFilename = sFilename & "1" & sEndung
If MsgBox("File """ & aFile(i) & """ will be " _
& "renamed To """ & sFilename & """" , _
1, "OK") <> 1 _
Then WScript.Quit
If Not oFSO.Fileexists(sFilename) Then
' oFSO.CopyFile aFile(i), sFilename
End If
End If
Next

-- End --

The script looks in the directory where it resides and copies all File to the same folder...

Try it first.

If it satisfies your needs the only things you have to do are the following..

Delete this code

If MsgBox("File """ & aFile(i) & """ will be " _
& "renamed To """ & sFilename & """" , _
1, "OK") <> 1 _
Then WScript.Quit

This is for the messagebox.

And uncomment this one

' oFSO.CopyFile aFile(i), sFilename


regards

Dirk
My System SpecsSystem Spec
Old 02-05-2009   #3 (permalink)
rodchar


 
 

Re: copy and rename into same dir

thanks for the help,
rod.

"Dirk Stegemann" wrote:
Quote:

> Hi rodchar,
>
> --
Quote:

> > is there an easy way to copy each file in my directory and paste into the
> > same diretory but with a number 1 appended to the filename?
> --
>
> hope this one helps you a little bit...
>
> --Start --
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oFolder = oFSO.GetFolder(".")
> ReDim aFile(500)
> i = 0
> For Each oFile In oFolder.Files
> aFile(i) = oFile.Name
> i= i+1
> Next
> ReDim Preserve aFile(i -1)
> For i = LBound (aFile) To UBound (aFile)
> If aFile(i) <> "" then
> sFilename = Left(aFile(i), InStr(aFile(i), ".") -1)
> sEndung = Mid(aFile(i), InStr(aFile(i), "."), _
> Len(aFile(i))- InStr(aFile(i), ".")+1)
> sFilename = sFilename & "1" & sEndung
> If MsgBox("File """ & aFile(i) & """ will be " _
> & "renamed To """ & sFilename & """" , _
> 1, "OK") <> 1 _
> Then WScript.Quit
> If Not oFSO.Fileexists(sFilename) Then
> ' oFSO.CopyFile aFile(i), sFilename
> End If
> End If
> Next
>
> -- End --
>
> The script looks in the directory where it resides and copies all File to the same folder...
>
> Try it first.
>
> If it satisfies your needs the only things you have to do are the following..
>
> Delete this code
>
> If MsgBox("File """ & aFile(i) & """ will be " _
> & "renamed To """ & sFilename & """" , _
> 1, "OK") <> 1 _
> Then WScript.Quit
>
> This is for the messagebox.
>
> And uncomment this one
>
> ' oFSO.CopyFile aFile(i), sFilename
>
>
> regards
>
> Dirk
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Copy/Move file and rename if destination exist PowerShell
In Vista Home Premium - Can not copy, move, rename or delete a fil Vista file management
Can the copy-item cmdlet be used to copy public folders to C: ? PowerShell
Rename errorin Vista - multiple file rename Vista file management
copy-item changing files attributes on network copy failures PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46