mcrmg
asked on
VBScript Moving & Rename files
Hi,
I am running into this problem, we will be likely buying this product from Adlibsoftware, it can convert TIF into PDFs, I have been working on the scripts that control the way that converts the files.
I have a following structure:
OrderID(FOLDER)
ProductName1(FOLDER)
TIF1
TIF2
ProductName2(FOLDER)
TIF1
TIF2
ProductName3(FOLDER)
TIF1
TIF2
Is there a way to loop through the OrderID folder and make the file structure like this:
OrderID(FOLDER)
ProductName1-TIF1
ProductName1-TIF2
ProductName2-TIF1
ProductName2-TIF2
ProductName3-TIF1
ProductName3-TIF2
Thx
I am running into this problem, we will be likely buying this product from Adlibsoftware, it can convert TIF into PDFs, I have been working on the scripts that control the way that converts the files.
I have a following structure:
OrderID(FOLDER)
ProductName1(FOLDER)
TIF1
TIF2
ProductName2(FOLDER)
TIF1
TIF2
ProductName3(FOLDER)
TIF1
TIF2
Is there a way to loop through the OrderID folder and make the file structure like this:
OrderID(FOLDER)
ProductName1-TIF1
ProductName1-TIF2
ProductName2-TIF1
ProductName2-TIF2
ProductName3-TIF1
ProductName3-TIF2
Thx
By the way, just copy the code from 'START CODE to 'END CODE, paste it into an empty text file, save it as 'moveTif.vbs' (or whatever) and run it from the root directory (in this case OrderID).
ASKER
hi,
It works great..Is it possible that it could be used in this way?
Instead of using . as current folder, can enterence folder be two levels up?
INPUT
***HERE***
Company
OrderID(FOLDER)
***current enterence folder***
ProductName1(FOLDER)
TIF1
TIF2
ProductName2(FOLDER)
TIF1
TIF2
ProductName3(FOLDER)
TIF1
TIF2
I am sorry that I shouldve mentioned it....thx
It works great..Is it possible that it could be used in this way?
Instead of using . as current folder, can enterence folder be two levels up?
INPUT
***HERE***
Company
OrderID(FOLDER)
***current enterence folder***
ProductName1(FOLDER)
TIF1
TIF2
ProductName2(FOLDER)
TIF1
TIF2
ProductName3(FOLDER)
TIF1
TIF2
I am sorry that I shouldve mentioned it....thx
Yeah, probably the best idea is just to use an absolute path - then you can run the script from anywhere on the machine's file system.
Instead of using . as current folder use "c:\whatever\Company\Order ID" So the relevant line will now look like this:
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder("c:\whatever \Company\O rderID")
Does that do the job for you?
Instead of using . as current folder use "c:\whatever\Company\Order
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder("c:\whatever
Does that do the job for you?
ASKER
This is what I did, but does not seem working....
'START CODE
Option Explicit
Dim fso: Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Main
Sub Main
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder("C:\Input")
CheckFolderNames CurrentFolder
End Sub
Sub CheckFolderNames (ByVal Folder)
Dim SubFolders: Set SubFolders = Folder.SubFolders
Dim SubFolder
Dim SubFolders1: Set SubFolders1 = Folder.SubFolders
Dim SubFolder1
Dim SubFolders2: Set SubFolders2 = Folder.SubFolders
Dim SubFolder2
Dim SubFolders3: Set SubFolders3 = Folder.SubFolders
Dim SubFolder3
Dim File
Dim n, newName
For Each SubFolder1 In SubFolders1
For Each SubFolder2 In SubFolders2
For Each SubFolder3 In SubFolders3
For Each SubFolder In SubFolders
Dim Files: Set Files = SubFolder.Files
For Each File In Files
newName = SubFolder.Name + "-" + File.Name
'if instr(file.type, "Tagged Image File") then 'remove this line (and the 'end if') if you want to move all files, not just tif files
File.Move fso.GetParentFolderName(Su bFolder) & "\" & newName
'end if
Next
'fso.DeleteFolder SubFolder.Name
Next
Next
Next
Next
End Sub
'END CODE
'START CODE
Option Explicit
Dim fso: Set fso = CreateObject("Scripting.Fi
Main
Sub Main
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder("C:\Input")
CheckFolderNames CurrentFolder
End Sub
Sub CheckFolderNames (ByVal Folder)
Dim SubFolders: Set SubFolders = Folder.SubFolders
Dim SubFolder
Dim SubFolders1: Set SubFolders1 = Folder.SubFolders
Dim SubFolder1
Dim SubFolders2: Set SubFolders2 = Folder.SubFolders
Dim SubFolder2
Dim SubFolders3: Set SubFolders3 = Folder.SubFolders
Dim SubFolder3
Dim File
Dim n, newName
For Each SubFolder1 In SubFolders1
For Each SubFolder2 In SubFolders2
For Each SubFolder3 In SubFolders3
For Each SubFolder In SubFolders
Dim Files: Set Files = SubFolder.Files
For Each File In Files
newName = SubFolder.Name + "-" + File.Name
'if instr(file.type, "Tagged Image File") then 'remove this line (and the 'end if') if you want to move all files, not just tif files
File.Move fso.GetParentFolderName(Su
'end if
Next
'fso.DeleteFolder SubFolder.Name
Next
Next
Next
Next
End Sub
'END CODE
ASKER
okay, it is working now, however, I need to delete those empty folders, it says "path not found"
This line:
fso.DeleteFolder SubFolder2.Name
thx
'START CODE
Option Explicit
Dim fso: Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Main
Sub Main
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder("C:\Input")
CheckFolderNames CurrentFolder
End Sub
Sub CheckFolderNames (ByVal Folder)
Dim SubFolders: Set SubFolders = Folder.SubFolders
Dim SubFolder
Dim File
Dim n, newName
For Each SubFolder In SubFolders
Dim SubFolders1: Set SubFolders1 = SubFolder.SubFolders
Dim SubFolder1
For Each SubFolder1 In SubFolders1
Dim SubFolders2: Set SubFolders2 = SubFolder1.SubFolders
Dim SubFolder2
For Each SubFolder2 In SubFolders2
Dim Files: Set Files = SubFolder2.Files
For Each File In Files
newName = SubFolder2.Name + "-" + File.Name
'if instr(file.type, "Tagged Image File") then 'remove this line (and the 'end if') if you want to move all files, not just tif files
File.Move fso.GetParentFolderName(Su bFolder2) & "\" & newName
'end if
Next
MsgBox SubFolder2.Name
fso.DeleteFolder SubFolder2.Name
Next
Next
Next
End Sub
'END CODE
This line:
fso.DeleteFolder SubFolder2.Name
thx
'START CODE
Option Explicit
Dim fso: Set fso = CreateObject("Scripting.Fi
Main
Sub Main
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder("C:\Input")
CheckFolderNames CurrentFolder
End Sub
Sub CheckFolderNames (ByVal Folder)
Dim SubFolders: Set SubFolders = Folder.SubFolders
Dim SubFolder
Dim File
Dim n, newName
For Each SubFolder In SubFolders
Dim SubFolders1: Set SubFolders1 = SubFolder.SubFolders
Dim SubFolder1
For Each SubFolder1 In SubFolders1
Dim SubFolders2: Set SubFolders2 = SubFolder1.SubFolders
Dim SubFolder2
For Each SubFolder2 In SubFolders2
Dim Files: Set Files = SubFolder2.Files
For Each File In Files
newName = SubFolder2.Name + "-" + File.Name
'if instr(file.type, "Tagged Image File") then 'remove this line (and the 'end if') if you want to move all files, not just tif files
File.Move fso.GetParentFolderName(Su
'end if
Next
MsgBox SubFolder2.Name
fso.DeleteFolder SubFolder2.Name
Next
Next
Next
End Sub
'END CODE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
Woo hoo! Got there in the end.
You're welcome.
You're welcome.
'START CODE
Option Explicit
Dim fso: Set fso = CreateObject("Scripting.Fi
Main
Sub Main
Dim CurrentFolder: Set CurrentFolder = fso.GetFolder(".")
CheckFolderNames CurrentFolder
End Sub
Sub CheckFolderNames (ByVal Folder)
Dim SubFolders: Set SubFolders = Folder.SubFolders
Dim SubFolder
Dim File
Dim n, newName
For Each SubFolder In SubFolders
Dim Files: Set Files = SubFolder.Files
For Each File In Files
newName = SubFolder.Name + "-" + File.Name
if instr(file.type, "Tagged Image File") then 'remove this line (and the 'end if') if you want to move all files, not just tif files
File.Move fso.GetParentFolderName(Su
end if
Next
Next
End Sub
'END CODE