Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default DIR Function Question

I'm trying to rename files and then move them to a new
folder. The code to rename works. The code to move
works. They don't work together. Attached is the complete
code. Files in the original folder will rename using the
filecopy. Kill works and the original file is gone but the
move never takes place. If I comment out the copy and
kill pharses then the move works fine. What am I doing
wrong?

Thanks
Mike

Sub TEST()
Dim oFSO As Object
Dim inFILE, outFILE, fNAME, fromFOLDER, toFOLDER

Set oFSO = CreateObject("Scripting.FileSystemObject")

inFILE = Dir("C:\DVW\REPORTS\")
fNAME = oFSO.getbasename(inFILE)
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE

Do While inFILE < ""
inFILE = Dir
fNAME = oFSO.getbasename(inFILE)
On Error GoTo OOPS
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE
Loop

fromFOLDER = "C:\DVW\REPORTS\*.XLS"
toFOLDER = "C:\DVW\REPORTS\D9\"

oFSO.movefile fromFOLDER, toFOLDER

Set oFSO = Nothing
OOPS:
If Err < 0 Then
Err.Clear
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default DIR Function Question

Maybe simpler to use FileCopy:

Sub test()

FileCopy "C:\File1.txt", "C:\File2.txt"
Kill "C:\File1.txt"

End Sub


RBS


"Mike" wrote in message
...
I'm trying to rename files and then move them to a new
folder. The code to rename works. The code to move
works. They don't work together. Attached is the complete
code. Files in the original folder will rename using the
filecopy. Kill works and the original file is gone but the
move never takes place. If I comment out the copy and
kill pharses then the move works fine. What am I doing
wrong?

Thanks
Mike

Sub TEST()
Dim oFSO As Object
Dim inFILE, outFILE, fNAME, fromFOLDER, toFOLDER

Set oFSO = CreateObject("Scripting.FileSystemObject")

inFILE = Dir("C:\DVW\REPORTS\")
fNAME = oFSO.getbasename(inFILE)
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE

Do While inFILE < ""
inFILE = Dir
fNAME = oFSO.getbasename(inFILE)
On Error GoTo OOPS
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE
Loop

fromFOLDER = "C:\DVW\REPORTS\*.XLS"
toFOLDER = "C:\DVW\REPORTS\D9\"

oFSO.movefile fromFOLDER, toFOLDER

Set oFSO = Nothing
OOPS:
If Err < 0 Then
Err.Clear
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default DIR Function Question

Why not just

Name "C:\File1.txt", "C:\File2.txt"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"RB Smissaert" wrote in message
...
Maybe simpler to use FileCopy:

Sub test()

FileCopy "C:\File1.txt", "C:\File2.txt"
Kill "C:\File1.txt"

End Sub


RBS


"Mike" wrote in message
...
I'm trying to rename files and then move them to a new
folder. The code to rename works. The code to move
works. They don't work together. Attached is the complete
code. Files in the original folder will rename using the
filecopy. Kill works and the original file is gone but the
move never takes place. If I comment out the copy and
kill pharses then the move works fine. What am I doing
wrong?

Thanks
Mike

Sub TEST()
Dim oFSO As Object
Dim inFILE, outFILE, fNAME, fromFOLDER, toFOLDER

Set oFSO = CreateObject("Scripting.FileSystemObject")

inFILE = Dir("C:\DVW\REPORTS\")
fNAME = oFSO.getbasename(inFILE)
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE

Do While inFILE < ""
inFILE = Dir
fNAME = oFSO.getbasename(inFILE)
On Error GoTo OOPS
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE
Loop

fromFOLDER = "C:\DVW\REPORTS\*.XLS"
toFOLDER = "C:\DVW\REPORTS\D9\"

oFSO.movefile fromFOLDER, toFOLDER

Set oFSO = Nothing
OOPS:
If Err < 0 Then
Err.Clear
End If
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default DIR Function Question

Bob,

You are right, I keep forgetting that one.
Still it was better than using the Scripting.FileSystemObject.

RBS


"Bob Phillips" wrote in message
...
Why not just

Name "C:\File1.txt", "C:\File2.txt"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"RB Smissaert" wrote in message
...
Maybe simpler to use FileCopy:

Sub test()

FileCopy "C:\File1.txt", "C:\File2.txt"
Kill "C:\File1.txt"

End Sub


RBS


"Mike" wrote in message
...
I'm trying to rename files and then move them to a new
folder. The code to rename works. The code to move
works. They don't work together. Attached is the complete
code. Files in the original folder will rename using the
filecopy. Kill works and the original file is gone but the
move never takes place. If I comment out the copy and
kill pharses then the move works fine. What am I doing
wrong?

Thanks
Mike

Sub TEST()
Dim oFSO As Object
Dim inFILE, outFILE, fNAME, fromFOLDER, toFOLDER

Set oFSO = CreateObject("Scripting.FileSystemObject")

inFILE = Dir("C:\DVW\REPORTS\")
fNAME = oFSO.getbasename(inFILE)
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE

Do While inFILE < ""
inFILE = Dir
fNAME = oFSO.getbasename(inFILE)
On Error GoTo OOPS
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE
Loop

fromFOLDER = "C:\DVW\REPORTS\*.XLS"
toFOLDER = "C:\DVW\REPORTS\D9\"

oFSO.movefile fromFOLDER, toFOLDER

Set oFSO = Nothing
OOPS:
If Err < 0 Then
Err.Clear
End If
End Sub





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default DIR Function Question

I agree. It was only seeing you questioning FSO that made me think of Name.

Regards

Bob


"RB Smissaert" wrote in message
...
Bob,

You are right, I keep forgetting that one.
Still it was better than using the Scripting.FileSystemObject.

RBS


"Bob Phillips" wrote in message
...
Why not just

Name "C:\File1.txt", "C:\File2.txt"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"RB Smissaert" wrote in message
...
Maybe simpler to use FileCopy:

Sub test()

FileCopy "C:\File1.txt", "C:\File2.txt"
Kill "C:\File1.txt"

End Sub


RBS


"Mike" wrote in message
...
I'm trying to rename files and then move them to a new
folder. The code to rename works. The code to move
works. They don't work together. Attached is the complete
code. Files in the original folder will rename using the
filecopy. Kill works and the original file is gone but the
move never takes place. If I comment out the copy and
kill pharses then the move works fine. What am I doing
wrong?

Thanks
Mike

Sub TEST()
Dim oFSO As Object
Dim inFILE, outFILE, fNAME, fromFOLDER, toFOLDER

Set oFSO = CreateObject("Scripting.FileSystemObject")

inFILE = Dir("C:\DVW\REPORTS\")
fNAME = oFSO.getbasename(inFILE)
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE

Do While inFILE < ""
inFILE = Dir
fNAME = oFSO.getbasename(inFILE)
On Error GoTo OOPS
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE
Loop

fromFOLDER = "C:\DVW\REPORTS\*.XLS"
toFOLDER = "C:\DVW\REPORTS\D9\"

oFSO.movefile fromFOLDER, toFOLDER

Set oFSO = Nothing
OOPS:
If Err < 0 Then
Err.Clear
End If
End Sub






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
IF function question Dutilbug Excel Worksheet Functions 9 April 7th 09 08:28 PM
Function Question SteveDB1 Excel Worksheet Functions 8 March 16th 09 02:23 PM
IF function question hispeaches Excel Worksheet Functions 1 July 11th 08 05:11 PM
Function Question JustOneJawa Excel Worksheet Functions 2 June 8th 06 08:43 PM
Help: Question Regarding Name Function Dustin Schofield Excel Programming 0 December 4th 03 02:16 PM


All times are GMT +1. The time now is 03:33 PM.

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

About Us

"It's about Microsoft Excel"