ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming (https://www.excelbanter.com/excel-programming/299143-renaming.html)

ianripping[_66_]

Renaming
 
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

--
Message posted from http://www.ExcelForum.com


Norman Jones

Renaming
 
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


---
Regards,
Norman


"ianripping " wrote in message
...
Not too sure if this is the related forum.

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

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

Kind Regards

Ian Ripping


---
Message posted from http://www.ExcelForum.com/




Rob van Gelder[_4_]

Renaming
 
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


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"ianripping " wrote in message
...
Not too sure if this is the related forum.

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

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

Kind Regards

Ian Ripping


---
Message posted from http://www.ExcelForum.com/




Bob Phillips[_6_]

Renaming
 
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)

"ianripping " wrote in message
...
Not too sure if this is the related forum.

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

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

Kind Regards

Ian Ripping


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 05:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com