![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||