Hello All,
I have many zip files in one folder and that need to be placed in different folder depending on the file name. what i want is that zip file should move to different folder where the folder name exist or maybe new folder should be created.
For example if the file name is R189_2282_LME and R189_4252_OME .... it will go in folder 2282 & 4252.
I had seen the code in the following thread
http://www.mrexcel.com/forum/showthread.php?t=446664
I modified it and the following code which is working fine..but its still incomplete.
Option Explicit
Sub MoveFiles()
'JBeaucaire (2/6/2010)
'Moves files from the desktop into folders of their own
Dim fName As String, fromPath As String, toPath As String, Cnt As Long
On Error Resume Next
toPath = "E:\Move\Output\"
fromPath = "E:\Move\Input\"
Restart:
If Cnt > 1 Then Exit Sub
fName = Dir(fromPath & "*.zip")
Do While Len(fName) > 0
If Cnt > 1 Then Exit Sub
Cnt = 0
If Len(Dir(toPath & Mid(fName, 6, 4), vbDirectory)) = 0 Then
MkDir toPath & Mid(fName, 6, 4)
'If Len(Dir(toPath & Right(fName, Len(fName) - 5), vbDirectory)) = 0 Then
'MkDir toPath & Right(fName, Len(fName) - 5)
End If
Name (fromPath & fName) As (toPath & Mid(fName, 6, 4) & "\" & fName)
'Name (fromPath & fName) As (toPath & Right(fName, Len(fName) - 5) & "\" & fName)
fName = Dir
Loop
Cnt = Cnt + 1
GoTo Restart
End Sub
What I need is 2 things
1) If the number after the file name is of 5 or 6 digit. the winzip file should move in that folder or new folder should be created. For example the file name is R189_2282, the folder name should be 2282, if the file name is R189_26932, the folder name should be 26932, if the file name is R189_398465, the folder name should be 398465.
2) When the winzip file is getting pasted it should create the current month folder in that path and paste itself in that folder. For example it will be like e:\xxx\2282\July'11
Please help me in this coding.
I have many zip files in one folder and that need to be placed in different folder depending on the file name. what i want is that zip file should move to different folder where the folder name exist or maybe new folder should be created.
For example if the file name is R189_2282_LME and R189_4252_OME .... it will go in folder 2282 & 4252.
I had seen the code in the following thread
http://www.mrexcel.com/forum/showthread.php?t=446664
I modified it and the following code which is working fine..but its still incomplete.
Option Explicit
Sub MoveFiles()
'JBeaucaire (2/6/2010)
'Moves files from the desktop into folders of their own
Dim fName As String, fromPath As String, toPath As String, Cnt As Long
On Error Resume Next
toPath = "E:\Move\Output\"
fromPath = "E:\Move\Input\"
Restart:
If Cnt > 1 Then Exit Sub
fName = Dir(fromPath & "*.zip")
Do While Len(fName) > 0
If Cnt > 1 Then Exit Sub
Cnt = 0
If Len(Dir(toPath & Mid(fName, 6, 4), vbDirectory)) = 0 Then
MkDir toPath & Mid(fName, 6, 4)
'If Len(Dir(toPath & Right(fName, Len(fName) - 5), vbDirectory)) = 0 Then
'MkDir toPath & Right(fName, Len(fName) - 5)
End If
Name (fromPath & fName) As (toPath & Mid(fName, 6, 4) & "\" & fName)
'Name (fromPath & fName) As (toPath & Right(fName, Len(fName) - 5) & "\" & fName)
fName = Dir
Loop
Cnt = Cnt + 1
GoTo Restart
End Sub
What I need is 2 things
1) If the number after the file name is of 5 or 6 digit. the winzip file should move in that folder or new folder should be created. For example the file name is R189_2282, the folder name should be 2282, if the file name is R189_26932, the folder name should be 26932, if the file name is R189_398465, the folder name should be 398465.
2) When the winzip file is getting pasted it should create the current month folder in that path and paste itself in that folder. For example it will be like e:\xxx\2282\July'11
Please help me in this coding.