MSFN Forum: Rename file using folder name - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rename file using folder name Rate Topic: -----

#1 User is offline   jmpadams 

  • Group: Members
  • Posts: 2
  • Joined: 25-October 07

Posted 25 October 2007 - 04:26 PM

I have an outside system that generates hundreds of folders with unique names. The group of files INSIDE each folder have the same names. For instance here is a sample of two folders with the files that are in each:

http://10.131.180.203/u/user/assets/ S-CA-WILDFIRE-LAKEWOOD
Script.txt
broadcast.mpg
preview.jpg
proxy.wmv
z_metadata.xml

http://10.131.180.203/u/user/assets/S-FIRS...UMBO-COMMERCIAL
Script.txt
broadcast.mpg
preview.jpg
proxy.wmv
z_metadata.xml

I want to copy the broadcast.mpg from certain folders to another computer to the directory: C:\Video\ -- but, the file name needs to change to a unique name.

This is how I envision it working:
1.) User navigates to the folder that contains the mpg video they need
2.) User invokes a VB script that will
a. Capture the name of the current folder (e.g. S-CA-WILDFIRE-LAKEWOOD)
b. Copy the broadcast.mpg file to C:\Video\
c. Rename the file S-CA-WILDFIRE-LAKEWOOD.mpg

If it helps, the file labeled z_metadata.xml includes an xml tag labeled asset_name that contains the same name as the folder. Perhaps it can be extracted.

Any help would be greatly appreciated.
Thanks.


#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,019
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 26 October 2007 - 10:16 AM

This is a example of getting just the folder name and copy a file using the folder name.

Quote

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Folder
Set Folder = Fso.GetFolder(Fso.GetParentFolderName(WScript.ScriptFullName))
'/-> Shows Only The Folder Name
 MsgBox Folder.Name,4128,"Folder Name"
'/-> Check To See If The File Is There
 If Fso.FileExists("New Text Document.txt") Then 
  Fso.CopyFile("New Text Document.txt"),(Folder.Name & ".txt"),True
 End If


Here is a link for making a dialogbox and selecting multiple files for copy.
This will only work on XP machine and no other OS.
Hey, Scripting Guy!

This post has been edited by gunsmokingman: 26 October 2007 - 10:27 AM


#3 User is offline   jmpadams 

  • Group: Members
  • Posts: 2
  • Joined: 25-October 07

Posted 26 October 2007 - 12:58 PM

Thank you! It works!

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy