VBS scripting Username and Date

Author Message
legacy

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 11/23/2011
  • Status: offline
VBS scripting Username and Date Wednesday, November 23, 2011 3:35 AM (permalink)
0
[Helpful answer received] / [List Solutions Only]
hey guys,
 
i have got a stupid question for you but i dont have a solution for this:
i want to copy a file --> example.txt
to a unc-path --> \\Servername\ExamplePath\
during the copy process the example.txt file should be renamed in the currently user who is logged on and the date--> \\Servername\ExamplePath\User1_23112011.txt
this is what i got:

dim example
set example = CreateObject("Scripting.FilesSystemObject")
Example.Copyfile "C:\ExamplePath\example.txt", "\\Servername\ExamplePath\", TRUE
 
now i need the rename process :( can anyone help me please?
 
<message edited by legacy on Wednesday, November 23, 2011 3:37 AM>
 
#1
    robwm

    • Total Posts : 118
    • Scores: 0
    • Reward points : 0
    • Joined: 3/10/2009
    • Location: Seattle, WA
    • Status: offline
    Re:VBS scripting Username and Date Wednesday, November 23, 2011 3:43 AM (permalink)
    0
    Will you run this script from the client computer or will it run remotely on the client from another source?
     
    Rob
     
    #2
      legacy

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 11/23/2011
      • Status: offline
      Re:VBS scripting Username and Date Wednesday, November 23, 2011 3:46 AM (permalink)
      0
      i will run it on the client :)
       
      #3
        robwm

        • Total Posts : 118
        • Scores: 0
        • Reward points : 0
        • Joined: 3/10/2009
        • Location: Seattle, WA
        • Status: offline
        Re:VBS scripting Username and Date Wednesday, November 23, 2011 4:32 AM (permalink)
        0
        One other question, are the source and target paths always the same? Also, does the source file name always remain the same?
        <message edited by robwm on Wednesday, November 23, 2011 4:33 AM>
         
        #4
          legacy

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 11/23/2011
          • Status: offline
          Re:VBS scripting Username and Date Wednesday, November 23, 2011 4:43 AM (permalink)
          0
          the source and target path are always the same... the source file name example.txt does not change but the target file name does change and dont remain the same it should be changed in username and date..
           
           
          #5
            robwm

            • Total Posts : 118
            • Scores: 0
            • Reward points : 0
            • Joined: 3/10/2009
            • Location: Seattle, WA
            • Status: offline
            Re:VBS scripting Username and Date Wednesday, November 23, 2011 4:57 AM (permalink)
            0
            [This post was marked as helpful]
            If you need DDMMYYYY, you'll have to do some string manipulation. Here you go:

            Option Explicit
            'Declare variables
            Dim sDate
            Dim sUserName
            Dim objFSO, wshShell
            Dim sSourceFile
            Dim sTargetPath
            Dim sTargetFileName

            'Initialize variabless
            sSourceFile = "C:\ExamplePath\example.txt"

            'Remove slashes from date
            sDate = Replace(Date(), "/", "")

            'Get current user
            Set wshShell = CreateObject("Wscript.Shell")
            sUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")

            'Set target file name and path
            sTargetFileName = sUserName & "_" & sDate & ".txt"
            sTargetPath = "\\server\share\" & sTargetFileName

            'Copy file and rename to network location
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.CopyFile sSourceFile, sTargetPath, True

            <message edited by robwm on Wednesday, November 23, 2011 5:17 AM>
             
            #6
              legacy

              • Total Posts : 4
              • Scores: 0
              • Reward points : 0
              • Joined: 11/23/2011
              • Status: offline
              Re:VBS scripting Username and Date Wednesday, November 23, 2011 5:01 AM (permalink)
              0
              thank you so much i ll try it out tomorrow :D
               
              #7
                59cobalt

                • Total Posts : 981
                • Scores: 91
                • Reward points : 0
                • Joined: 7/17/2011
                • Status: offline
                Re:VBS scripting Username and Date Wednesday, November 23, 2011 10:32 AM (permalink)
                0
                robwm
                'Remove slashes from date
                sDate = Replace(Date(), "/", "")
                Beware that this will only work if your system's date format is DD/MM/YYYY. Better do it like this:
                today = Date
                sDate = Right("0" & Day(today), 2) & Right("0" & Month(today), 2) & Year(today)

                 
                #8

                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • New Messages
                  • No New Messages
                  • Hot Topic w/ New Messages
                  • Hot Topic w/o New Messages
                  • Locked w/ New Messages
                  • Locked w/o New Messages
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2012 ASPPlayground.NET Forum Version 3.9