Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming and moving files

Status
Not open for further replies.

manguilla

Programmer
Jul 20, 2004
52
US
Hello everyone. I am trying to find out if I should use VB for this project. I need to go to a specific folder on the c: drive, rename all the files in a sequential order (ex: filname1date, filename2date, filename3date), move the files to another folder and that's it. I want to build a program and have it run daily under scheduled tasks. Is there an easy way to do this with VB or should I try a freeware application? Thanks everyone
 
Look into the FileSystemObject. You can do this pretty simply.

Swi
 
Here´s a way to do it without using the FileSystemObject.
It will take all files in strDir and rename them to "filename_number.txt", and at the same time move them to
strDest.


Private Sub Command1_Click()
Dim strDir As String, strSource As String, strNew As String, strDest As String
Dim i As Integer

'The directory that contains the files
'that you want to rename
strDir = "C:\Test\"

' New dir to move files to
strDest = "C:\Test2\"

'Get the first file
strFile = Dir(strDir & "*.*")

Do While strFile <> ""
i = i + 1
'The file to rename
strSource = strDir & strFile
'The new file name containing the new path, which will also move it
strNew = strDest & "filename_" & i & ".txt"
'rename the file
Name strSource As strNew
'get the next file
strFile = Dir
Loop

End Sub


Cheers!
Maverick
 
Thanks NWNinja for all the help. I was able to make the .exe just fine and it works great except I can't get the file to copy over into the new directory. Is there something else that I need to do in the code or the folder? Thank again.

Manguilla
 
take a look at the Name As function

Everybody body is somebodys Nutter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top