dos copy

i have a slight problem when i am grabbing a file via a script and want to rename it. i want to rename it with a variable that is determind from another script but i want to rename it by adding the aariable to the begining of the origianl file name
DOS and use a copy command such as c:\dtt*.csv c:\dest%random%*.csv the only problem with this is that the varibble that you pass infront of the wild card replaces the first few characters (same amount of the variable) witht he variable not adding to it.

anyidea of how i can do this for its slightly driving me insane!

thanks all!

Can’t be done with a one line copy IMHO because you cannot provide input wildcards whilst specifying an output file name, you need a script or a VB script.

Unfortunately there my recollection of DOS commands ends :frowning:

I would do it in VB like this:

Hold the Variable Name so you can kill it later
Read file Binary into String
Write out with new name
Kill old file

Seems simple enough. Hope that gives you an idea or two.

thanks for the replys.

i will have to give it a go with VBS, even knowing i cant really do it, but will give it a good go!

this will copy a file from one location to another, adding the date to the begining of the file name, anything like what you need?

Option Explicit

dim wshshell, objfs,filename,thedate,source,destination,original,target
set objFS = CreateObject("Scripting.FileSystemObject")

filename = "testfile.txt"
thedate = datepart("d",now()) & "-" & datepart("m",now()) & "-" & datepart("yyyy",now()) & " "
Source = "c:	est\source\"
destination = "c:	est\destination\"

original = source & filename
target = destination & thedate & filename
objfs.copyfile original, target

msgbox "Done"

Wscript.Quit


Public F1, F2, F3, ff as String
Public Fod2,Fod1

F1 = “C:\Your PATH for Directory”
ff = “*.csv”
Call FileSearch(F2, ff)
If Len(Found2) > 6 then ’ Length depends on your file size
FileCopy Fod1 & Fod2, “C:\Final Path\Name you wish” & “.csv”
Kill Fod1 & Fod2 ’ Only if you need to delete first file
End if

Function FilesSearch(thepath As String, Ext As String)

Dim unkndir() As String
Dim tempdir As String
Dim ff As String
Dim DirCount As Integer
Dim X As Integer
DirCount = 0
ReDim unkndir(0) As String
unkndir(DirCount) = ""
If Right(thepath, 1) <> "\" Then
thepath = thepath & "\"
End If
DoEvents
tempdir = Dir(thepath, vbDirectory)
Do While tempdir <> ""
If tempdir <> "." And tempdir <> ".." Then
If (GetAttr(thepath & tempdir) And vbDirectory) = vbDirectory Then
unkndir(DirCount) = thepath & tempdir & "\"
DirCount = DirCount + 1
ReDim Preserve unkndir(DirCount) As String
End If
End If
tempdir = Dir
Loop
ff = Dir(thepath & Ext)
Do Until ff = ""
Fod1 = thepath ' & ff
Fod2 = ff

 ff = Dir
 
 Loop

 'searches through all sub direictories

 For X = 0 To (UBound(unkndir) - 1)
 FilesSearch unkndir(X), Ext
 Next X
 End Function

WOW…thanks guys, lots for me to attepmt here!