Renaming

I

ianripping

Not too sure if this is the related forum.

I want to create a batch file that looks at file 1's name, copies tha
and then looks at file 2's name and copies that and then it rename
file 1 with file 2's name and vice versa.

Any ideas? Can it be done with batch programming or does it have to b
done in C++ or java or can it be done in vba?

Kind Regards

Ian Rippin
 
N

Norman Jones

Hi Ian,

If your files are (say) C:\One.txt and C:\Two.txt, just use a temporary
intermediate file, say C:|\Temp.txt,

Sub SwitchFileNames()

Name "C:\One.txt" As "C:\Temp.txt"

Name "C:\Two.txt" As "C:\One.txt"

Name "c:\Temp.txt" As "C:\Two.txt"

End Sub
 
R

Rob van Gelder

As a batch file:
ren %1 %1.temp
ren %2 %1
ren %1.temp %2

then call it like:
mybatch.bat file1.txt file2.txt
 
B

Bob Phillips

Morning Ian,

Here is a simple little VBScript that does it.

Dim temp, myFile1, myFile2, oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

With oFSO
Set myFile1 = .GetFile("C:\myTest\Volker1.xls")
myFile1.Copy ("C:\myTest\temp.xls")
Set temp = .GetFile("C:\myTest\temp.xls")
Set myFile2 = .GetFile("C:\myTest\Volker2.xls")
myFile2.Copy ("C:\myTest\Volker1.xls")
temp.Copy ("C:\myTest\Volker2.xls")
temp.Delete
End With


Just put it in a text file, save it as Rename.vbs, and then you can run it
simply by double-clicking the file.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top