Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Visual Basic





See Related Forum Messages: Follow the Links Below to View Complete Thread

Copy -> Move -> Rename [solved]
Is it possible for an app to make a copy of itself, move the copy to another directory (create 1 if not created) and then rename the copy?

Newbie ! Copy And Rename Worksheet
I'm a real beginer with VBA so am just trying to learn from other's codes and hope for the best

Can someone help me fix the below. It's to copy a sheet called BLANK and then rename the new sheet the contents of cell L1 of sheet INDEX. I can get the below to copy, but not rename :


Code:
Sub CreateGateway1()
'
' CreateGateway1 Macro
' Macro recorded 01/09/2005 by Nyanko
' Application.DisplayAlerts = False
Sheets("BLANK").Select
Sheets("BLANK").Copy After:=Sheets(2)
Sheet.Name = Worksheets("Index").Range("L1").Value
Sheets("INDEX").Select
checkerr = MsgBox("Record Created")
End Sub

How To Write Code To Copy And Rename File In The Same Directory
a file needs to be copied and then renamed ,---all in the same directory, how to do that? the tough part is it won't let me copy the file to the same directory with the same file name, but I have to copy it first and then I could rename it.

any help?

Copy/Move Directory
Does anyone know how I can move or copy a directory and all it's subdirectories/files from one location to another? I've found a bunch of references on how to copy/move files, but I can't seem to do entire folders.

How To Copy/move Files Of Certain Extensions From One Directory To Another?
I am almost finished a small project and all that is left is figuring out how to move/copy files of certain extensions (.mov, .jpeg, etc) from Directory1 to Directory2... I have both directories, and the file extensions prepped already, but just need to know how I go about 'grabbing' the appropriate files and moving/copying them to the new directory. I've looked at FileSystemObject and can find no clues as of yet.

Anyone have any ideas on this one?

Thanks

Liberty in my lifetime!

Copy W/ Archive Tag
hi,

how can i copy a folder, however only copy it if the archive tag is set? and then once it is copied, it removes the archive tag?

ta

(please dont tell me to use xcopy!!)

Archive PPT-Save A Copy With Todays Date, If Doesnt Exist Already
I want to make a macro that will check a certain directory for a file with a filename like:

Presentation-20-09-2007.ppt

If the file for todays date doesnt exist, it saves the current presentaion with the proper date in the filename.

Is that possible?

Just Move A Directory, Into An Exsisting Directory, Replacing All Files That Exsist .
Just Move a directory, into an exsisting directory, replacing all files that exsist , if i am moving the directory to, and the file already exsists there,

Just like in Windows Explorer,


How do i do this?

Rename And Move To Next Sheet
Does anyone know the proper way to rename the current sheet, and move to the next one for "VBscript"? I thought that this would work...but it isn't working properly. It renames the first sheet but doesn't go past the second.


Code:
intSheet = 1 'counter for sheets

objExcel.Sheets("Sheet" & intSheet).Select 'select current sheet
objExcel.Sheets("Sheet" & intSheet).Name = strComputer 'rename current sheet as the computername

intSheet = intSheet + 1 'counter to add next sheet

objExcel.Sheets("Sheet" & intSheet).Select 'go to the next sheet

Rename Files And Move
hi,

i have a problem. i want to rename all files in a specific folder.
I don't know how to do this.
I want to change them like this:

all files end with .mp3
i want to rename all files like this:

*.mp3 --> *v.mp3

Can anyone help me??

thanks alot

akim123

Move And Rename File
This code will MOVE a file from the START to the END directory. I'd also like to rename the files by adding a Z.

Before:

test1.txt
test2.txt

After:

test1Z.txt
test2Z.txt



VB Code:
Private Sub cmdMove_Click()    On Error GoTo MyError        cmdMove.Enabled = False    MoveFiles "C:AaronStart", "C:AaronEnd", "txt"    cmdMove.Enabled = TrueMyError:   If Err.Number = 58 Then   MsgBox "File Exixts", vbOKOnly + vbExclamation   cmdMove.Enabled = True   End IfEnd Sub Private Sub MoveFiles(ByVal sSource As String, ByVal sDest As String, Optional ByVal sExt As String = "*")    Dim sFile As String    If Not Right$(sSource, 1) = "" Then sSource = sSource & ""    If Not Right$(sDest, 1) = "" Then sDest = sDest & ""    sFile = Dir(sSource & "*." & sExt)    Do While Len(sFile)        Name sSource & sFile As sDest & sFile        sFile = Dir    LoopEnd Sub

Move And Rename Sequentially ??Help??
I have tried everything to move files from one directory to another another and renaming them sequentially.

Example: view_1.jpg, View_2.jpg, View_2.jpg, etc...

I also need to check if the file already exists and if so rename the new file to the next number in the series.  I have searched the net and tried several codes with no luck.

So far I can move the files rename with no sequential numbering and no check fo existing files.

Does anyone have any ideas?

Thanks

Move Rename Problem
hello everyone...i have read an article on this forum
(http://www.vbcity.com/forums/faq.asp?fid=9&cat=System&#TID15799) abou renaming getting size and deleting a file
However there must be something wrong with it as i the program cannot move and rename the file to a specified folder as it sais.
anyone knows where the problem might be?
i am including an attachement with the project

thnx

Count Files In A Directory, AND Sub Directory, - Copy A Directory...
Hi,.

how do u:

1) count how many files are in a directory, and its sub directory?

2) How do you copy a directory, AND count how many files out the directory has been copied?


Wayne

EASY! HELP! HELP! Move And Rename A File
I have an application that opens a text file that it recieves daily via ftp. It appends all of the data in the text file to a SQL7 db and then closes the db connection. I then need the program to move the file to a different folder and rename it with a new file name. What code can I use to handle the moving and renaming?

File Move, Rename In As Few Steps As Possible
Hi guys,

I have a situation where I may need to move files owned by a user.

For example, user "fred" may own the following files in the "FR" directory:-

FRFRED44-010103-1947.ZIP
FRFRED44-010303-1143.ZIP

I may need to rename the user fred, which means his files have to be renamed and moved.

Example. User "FRED44" gets renamed to "SMITH67".

Therefore the files need to be renamed

SMITH67-010103-1947.ZIP
SMITH67-010303-1143.ZIP

and the files *moved* to the "SM" directory.

From where I see it, I would need to do this:-

1. Find all files that match "FRED44"
2. Copy all files to the "SM" directory
3. Rename the files "FRED44*.ZIP to "SMITH67*.ZIP"
4. Delete all the FRED44 files in the FR directory.

Is there a file management API that can do the above - move and rename - in one operation?

(No special reason for one operation - just efficiency).

Would that File API support the use of * as the renaming wildcard? As we know good old DOS supports *.

"XCOPY FRED44*.ZIP C:SMSMITH67*.ZIP"

Comments/code most welcome.

Thanks,

Mark

Move File Method And Rename Question
I am attempting to move a file and rename it. The code I am currently trying to use is:

[My.Computer.FileSystem.MoveFile("C:My DocumentsFile2*.xls", "C:My DocumentsSalesProcessed2.xls")]

I am getting a compile error.

Any thoughts?, please advise.

Belstoy



Rename A Directory
Could anyone tell me how to rename a directory to the
current date using vb?

Rename Directory
I like to rename a directory like this:

Text1.Text is the project number

then I like to rename the dir "prj" to "prj + project number".

Now i've try to do it with shell command, but I can't get it right:
Shell ("rename C:Testprj prj " & Text1.Text)

in MsDos the command is:
rename C:Testprj "prj 123456" <<< With " and " around the new name

Can somebody help me to correct my code?

Rename Directory
Hi Someone help me


I Have 1858 directories with files in to rename. How can i speed this job ?


Thanks



JP III

Directory Rename Help Me
Hai Friends,

i am working on a project which will display the directories in a treeview and i am trying to rename a folder its renamed but after i unloaded the form it is again getting its original name what to do? can u give me some idea to keep the original name to the directory?




thank you very much


srikanth

Rename A Directory?
Is there an API function that will rename a directory? Otherwise I'll have to create a new one, move all the files, and then delete the old one...

Cheers for the help!

Mafro

Rename Directory & Files
I have a directory with this name 1010001.imp, the directory contents files in this format : f001.tif.imp.
How would I rename the directory from 1010001.imp to 1010001 and all the contents from f001.tif.imp to f001.tif?
Now I do this from dos (ren *.imp *.tif).
I really need a code example to rename directory and contents in one press button.

Thanks in advance!
Andy

Rename Files In Directory Using Date
hi, i want to rename files in a directory looking like this:

Mvc-001.jpg
Mvc-054.jpg
Mvc-351.jpg
Mvc-672.jpg

look like this:

001s.jpg
002s.jpg
003s.jpg

by watching the date and time of creation. So when i took a picture on 23th september 2001 at 22.15 and 1 on 3th september 2001 at 22.16 the first is named 002.jpg and the second 001.jpg

Copy All Files In Current Directory To Temp Directory
ok heres the situation, i need to copy all the files in the app.path directory to another directory....the problem is, with the current code, i can run the app from a folder on the hdd fine, but i get an error when trying to run the app from the root directory of the cdrom....heres my code...btw apppath is a function which returns "D:" when running from the cdrom

error is invalid procedure argument or call, on the copy function


VB Code:
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long'--------    Dim fso As New FileSystemObject    Dim Folder2Copy As Folder    Set Folder2Copy = fso.GetFolder(AppPath)    If Not fso.FolderExists(TempPath & "InternetSignup") Then fso.CreateFolder TempPath & "InternetSignup"        Folder2Copy.Copy TempPath & "InternetSignup", True'--------Private Function TempPath() As String    'Function to control the TempPath API    Dim strBuffer As String    Dim lngLen As Long    lngLen = 1024    strBuffer = Space(lngLen)        If (GetTempPath(lngLen, strBuffer) > 0) Then        strBuffer = Left(strBuffer, InStr(1, strBuffer, vbNullChar) - 1)    Else        strBuffer = ""    End If        TempPath = strBuffer    End Function



EDIT: Resolved by moving all files to a subfolder on the cdrom

Active Directory - Rename Of An User Account
Hi, how can I change attributes of a user in visual basic or vbscript?

I know how to change the display name or description but I canīt change the user.cn or user.name.

Is there any way?

Copy And Rename File
I am trying to figure out how I can easily take a file stored on my HD and copy and paste with a different name. I've read something about FSO and My.Computer.FileSystem objects but don't know anything about them. The routine will take a blank database copy and rename and then place with ADO place data inside. Thanks for the help.

Wes

Copy/Rename File
I'm looking for a way to rename file through MS Access.
I've tried Rename Source, Destination, but this deletes the orignal file and renames it to another file in a different place. I want to keep the original copy where it is, but rename it as a text file on another drive.
Any ideas?

Copy, Paste, And Rename
Hi Guys,

This is prob. a simple question but i have no idea how to do this :

How do i make a copy of "Sheet1" and change the name of the copied sheet to "Sheet2"

Thanks in advance

Haj :O)

Copy/rename Worksheet
How do I copy a sheet "Input Form" and rename it to "Input Form n", where 'n' is a sequential number? All the copied sheets must be in the same workbook (hence the sequential numbering).

My code is:
---------------
'Code to determine new name
Dim sh As Worksheet
n = 0
For Each sh In ActiveWorkbook.Sheets
shname = ActiveSheet.Name
If Left(shname, 10) = "Input Form" Then n = n + 1
Next sh

Sheets("Input Form").Copy Before:=Sheets("Input Form")
ActiveSheet.Name = newName 'the "newName" variable is defined elsewhere
-----------------

I am having two problems:

1. My value for 'n' is always counting the total number of worksheets in the workbook (which is currently 6), instead of the number of worksheets whose name starts with "Input Form" (which is 1).

2. The code finishes after the .Copy line. Any code I place after this line is never run.

Any thoughts? Thanks!

Database Copy And Rename
I would like to create a back-up of my database before I import stuff in it. Its located in a folder (ex. C:datadatabase.mdb) and i would like to put it a backup folder with the date as part of the new database name (ex. C:dataackupdatabase5.4.01.mdb).

Any idea?

Also, since im in here, Is there a way to automatically compact the Database in Access97 from VB?

Thanks!

Open, Rename, Copy
I need to know the following things:

1. How to let the user rename a file (eg. When they type "C: ext.txt" into a box and "C: ext2.txt" into another, it will rename the file.)

2. The same thing except instead of renaming, to copy.

3. Similar, but I want it so that the user can type "C: ext.txt" and it will open it in Notepad.

Thanks for your help

Orufet Yatoehk
http://orufet.9ug.com

How To Rename Files And Copy Them Into New Dir
Hello i got more files and i first want to rename then copy them to the other map(renamed files).

And that files r w/o extension. So they r just files.


So in fact i wanna like that (dont forget there is a lot of files)




im coding in vb6

**RESOLVED** Copy And Rename
i have a file saved as C:Test.xls

I would like to take a copy of the file and rename it to C:Test_ABC.xls

does anyone have some code to do this?

Many thanks in advance.

Copy And Rename My Table
hi all ,
1:- i have create my db and my table in access as (table1),
2:- i have create vb product 1 form contains texts ,click buttons
as addnew, edit ,cancel, delete, save and datacontrol connected
to the table,
my db located ("c:my documents est est1.mdb")

could i copy my table in same db ,by using vb code and rename the new copy table using
text2.text="newname"
anyone has any adia pls. help
thanks

Copy/rename Files
How do I copy a file to a different folder and rename it?

Copy, Delete, Rename
Hi,
The following is well known code to most of VB programmers, right?

How can I rename the folder after I use the copy and delete?
Copy and Delete woked fine, but rename gave an error msg it says the folder is being used by another program!!
What's wrong?

 Public Const FO_MOVE As Long = &H1
      Public Const FO_COPY As Long = &H2
      Public Const FO_DELETE As Long = &H3
      Public Const FO_RENAME As Long = &H4

      Public Const FOF_MULTIDESTFILES As Long = &H1
      Public Const FOF_CONFIRMMOUSE As Long = &H2
      Public Const FOF_SILENT As Long = &H4
      Public Const FOF_RENAMEONCOLLISION As Long = &H8
      Public Const FOF_NOCONFIRMATION As Long = &H10
      Public Const FOF_WANTMAPPINGHANDLE As Long = &H20
      Public Const FOF_CREATEPROGRESSDLG As Long = &H0
      Public Const FOF_ALLOWUNDO As Long = &H40
      Public Const FOF_FILESONLY As Long = &H80
      Public Const FOF_SIMPLEPROGRESS As Long = &H100
      Public Const FOF_NOCONFIRMMKDIR As Long = &H200

      Type SHFILEOPSTRUCT
         hwnd As Long
         wFunc As Long
         pFrom As String
         pTo As String
         fFlags As Long
         fAnyOperationsAborted As Long
         hNameMappings As Long
         lpszProgressTitle As String
      End Type

      Declare Function SHFileOperation Lib "Shell32.dll" _
         Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
 
'------------------------------------------------------------------------------------------- Copy.
     Private Sub Command1_Click()
         Dim result As Long
         Dim fileop As SHFILEOPSTRUCT
         With fileop
            .hwnd = Me.hwnd
            .wFunc = FO_COPY
            .pFrom = "C:MyFolder*.*" & vbNullChar & vbNullChar
             .pTo = "C: estfolder" & vbNullChar & vbNullChar
            .fFlags = FOF_SIMPLEPROGRESS Or FOF_FILESONLY
         End With
         result = SHFileOperation(fileop)
         If result <> 0 Then 'Operation failed
            MsgBox result, , "Copy Operation Failed"
         Else
            If fileop.fAnyOperationsAborted <> 0 Then
               MsgBox fileop.fAnyOperationsAborted, , "Operation Aborted"
            End If
         End If
      End Sub
'------------------------------------------------------------------------------------------- Delete.
      Private Sub Command2_Click()
         Dim DelFileOp As SHFILEOPSTRUCT
         Dim result As Long
         With DelFileOp
            .hwnd = Me.hwnd
            .wFunc = FO_DELETE
            .pFrom = "C:MyFolder*.*" & vbNullChar & vbNullChar
            .fFlags = FOF_ALLOWUNDO
         End With
         result = SHFileOperation(DelFileOp)
         If result <> 0 Then 'Operation failed
            MsgBox result, , "Delete Operation Failed"
         Else
            If DelFileOp.fAnyOperationsAborted <> 0 Then
               MsgBox DelFileOp.fAnyOperationsAborted, , "Operation Aborted"
            End If
         End If
      End Sub

'------------------------------------------------------------------------------------------- Rename.
Private Sub Command3_Click()
         Dim result As Long
         Dim fileop As SHFILEOPSTRUCT
         With fileop
            .hwnd = Me.hwnd
            .wFunc = FO_RENAME
            .pFrom = "C:MyFolder" & vbNullChar & vbNullChar
             .pTo = "C:MyFolder-X"
            .fFlags = FOF_SIMPLEPROGRESS Or FOF_FILESONLY
         End With
         result = SHFileOperation(fileop)
         If result <> 0 Then 'Operation failed
            MsgBox result, , "Rename Operation Failed"
         Else
            If fileop.fAnyOperationsAborted <> 0 Then
               MsgBox fileop.fAnyOperationsAborted, , "Operation Aborted"
            End If
         End If
      End Sub

      Private Sub Form_Load()
         Command1.Caption = "Copy Test"
         Command2.Caption = "Recycle Test"
        Command3.Caption = "Rename Test "
      End Sub


 

Edited by - mrali on 6/2/2006 11:10:56 PM

{Resolved }How Do I Rename A Directory Using A Visual Basic 6 Program?
I have written a program that renames files in the format "yyyy.mm.dd hhmmss filename.xxx" to "yyyy-mm-dd hhmmss filename.xxx", and now it turns out it is also supposed to rename directories as well. Does anyone know how I can accomplish this in Visual Basic 6? I did a thorough search of VBcity, and all I could find was a method for doing this in VB.NET. Any help would be greatly appreciated.

Thanks,
Zig


"Remember, no matter where you go... there you are."
- Buckaroo Banzai

Edited by - zigwaffle on 7/20/2004 6:28:12 AM

Copy And Rename .jpg File Problem
Hi All, I'm in the process of writing a piece of VBA code in Access 2000 which will check for the existance of a .jpg file and then copy and rename the file to another directory if it exists. I have used the FileSystemObject in the past to move text files but I get a runtime error 13, type mismatch when trying to move an image file.

VB:

If LookForFile(conPicturePath, pstrFileName) = True Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CopyFile(conPicturePath & pstrFileName, "C:DatabaseUpload" & pstrVIN & conFileExtension)

rsRenamePicture.Edit
rsRenamePicture!fldPictureUploaded = True
rsRenamePicture.Update

Set fs = Nothing
Set f = Nothing
'If not, then write TransID to errorlog.txt
Else
Call WriteErrorLog(pstrTransID)
End If

End VB:

Any thoughts.

Thanks

`JB

Problem Using File Copy And Rename
Hi all i am trying copy a perticuler file and rename it on click of button but it does not work. Could any one tell me what i am doing wrong.Thanks


Code:
Private Sub Command2_Click()
FileCopy C:Program Filesprogprog.exe , C:Program Filesprogprog001.exe

end sub

File Copy And Rename Code -any 1 Know It?
hi,

i have a problem finding code to copy and rename files (please see the enclosed thumbnail)

the user is supposed to browse for the file in the text box and when u click on comnad button 9 it copys to a set location and renames them to set filoenames

so if a file was in textbox1 it would be renamed to file1. what ever

if a file was in textbox2 it would be renamed to file2. what ever

any help is apreaseated

Copy And Rename Access Tabla...
Hi everybody

How can i copy and rename a table with code from VB6?

Tks

COPY AND RENAME When I Press A Command Button
I want to know how can I have a commandbutton1, so when I press
it that COPIES a specific file (lets say TEST.MDB) from the application
path to a network computer (lets say to the USER5CBACKUPS folder
which of course it is shared and i have permissions to write etc.

Another similar situation is instead of copying using commandbutton1 but commandbutton2 to RENAME
the TEST.MDB mentioned above to lets say NEWTEST.MDB

I suppose this is kind SHELL command but I am not familiar with it because
I guess you run only a EXE file and not a total of DOS commands

Thanx a lot for your time

Search,copy,rename,delete Files
can u guys give me a code that can search, copy,rename, or delete files? i want to make an application just like explorer

Copy, Rename And Open A File Through Command Button
hey all!
i need help plz!
i have an access file .mdb
i need a command button code that copies, renames and open dat mdb file.
the user should enter the name of the new file through a textbox on the form.
can anybody help plz!

Move Directory
I have a couple of questions. I have a form that I need to MOVE files from one directory to another. I know how to move single files, the code I have now is:

Private Sub Command1_Click()
Dim FileSystemObject As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
FileSystemObject.MoveFile "o:GISUnmappped259G.dwg", "d:NewWorkOrder259G.dwg"
End Sub

However I will not know the names of the files to be moved, so I need to move the contents of the directory to the other diretory. I can't copy because the o: directory has to be emptied.

Also I have the code in a Command button for this example but I need to know how to make this run "unseen"

Thanks for any help,

JO

How To Move Type Lib To New Directory?
Hi,
I have this type library that I've been using with one project. Now I wish to move the library to a new folder and access it from a new project. But when I open Project|References the library is still listed in the list as being located in the old directory. I have tried the following:
1) unregistering the library -> get message saying it was never registered.
2) deleting the library from the old folder and then using Browse from References to locate it in the new directory.
What's worse is that I know its possible for I've done it before but can't remember the correct magic incantation.

Can anyone help me?

How To Move A File Into Another Directory?
>I am a new one in VB programming.
>How to move a file form one directory to another?
>Thank you in advance.

I should say I am a new one in VBA for Access programming. Sorry for misleading.

Serran, does your code work in VBA for Access 2000?

Copyright Đ 2005-08 www.BigResource.com, All rights reserved