#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming Pictures DJDKAL[_2_] Excel Discussion (Misc queries) 0 July 17th 08 07:19 PM
VB file renaming. El Bee Excel Worksheet Functions 2 January 23rd 08 01:49 AM
RENAMING cells WLMPilot Excel Discussion (Misc queries) 3 December 13th 07 10:57 PM
Workbook renaming! aiyer[_21_] Excel Programming 1 May 12th 04 08:03 PM
Renaming within VBA Brent McIntyre Excel Programming 4 August 21st 03 02:10 AM


All times are GMT +1. The time now is 02:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"