SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 9 of 9
  1. #1
    Senior Member
    Join Date
    Oct 2010
    Posts
    189
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    delete files from My Documents folder

    Hello All,

    Please let me know how can i delete the files

    the scenario is like this. if log with john credentials it will delete the files as given in the script below.
    the sample files are copied onto my documents folder of respective users.
    The script is general for all users eg. tom, tony, sarah etc.,
    how can i delete the file based on the user credentials. if tom logs with his credentials the script should delete the files from tom folder of my documents.
    Set f = CreateObject("Scripting.FileSystemObject")
    f.DeleteFile("C:\Documents and Settings\My Documents\john\Test1.txt")

    thank you for your help in advance.

  2. #2
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    Get the logged in user and pass that to the script.

    LoggedUser = Environment("UserName")

    FilePath = "C:\Documents and Settings\" & LoggedUser & "\My Documents\Test1.txt"

    Set f = CreateObject("Scripting.FileSystemObject")
    f.DeleteFile FilePath
    Rajkumar

  3. #3
    Advanced Member
    Join Date
    Nov 2007
    Location
    India
    Posts
    686
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    1.You might consider parameterization of path of file to be deleted.
    2.You can get user name from environment and concatenate user name in path.
    3.Only constraint is my document folder or for that matter any user folder would only be accessible for Administrative user.
    Kind regards,
    Anand Tambey

    RSS Feed : Break To Make it Better
    A Lazy person could be the best automation professional, if he is not lazy in implementing his ideas to reduce his work. ~Anand Tambey

  4. #4
    Senior Member
    Join Date
    Oct 2010
    Posts
    189
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder


    Msgbox returns & UserName & ")

    LoggedUser = Environment("UserName")

    MsgBox ( "& UserName &" )
    exitrun
    FilePath = "C:\Documents and Settings\" & LoggedUser & "\My Documents\Exe.txt"

    Set f = CreateObject("Scripting.FileSystemObject")
    f.DeleteFile FilePath

  5. #5
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    You have to remove the double quotes & replace UserName with LoggedUser.

    LoggedUser = Environment("UserName")
    MsgBox LoggedUser

    FilePath = "C:\Documents and Settings\" & LoggedUser & "\My Documents\Exe.txt"

    Set f = CreateObject("Scripting.FileSystemObject")
    f.DeleteFile FilePath
    Rajkumar

  6. #6
    Senior Member
    Join Date
    Oct 2010
    Posts
    189
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    i Get file not found window. but the file is there and i am able to delete the file manually.

  7. #7
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    Are you sure about the path?

    I had changed your script in your original post.

    From This ...
    f.DeleteFile("C:\Documents and Settings\My Documents\john\Test1.txt")

    to this...

    FilePath = "C:\Documents and Settings\" & LoggedUser & "\My Documents\Exe.txt"

    And that might be the issue. So you could actually try using the correct file path.

    FilePath = "C:\Documents and Settings\My Documents\" & LoggedUser & "\Exe.txt"
    Rajkumar

  8. #8
    Senior Member
    Join Date
    Oct 2010
    Posts
    189
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    sorry for the delay in reply i was pulled out of scripting to test EQF work on another application.

    The script worked and thank you Raj for the heads up and appreciate your help

    john

  9. #9
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: delete files from My Documents folder

    Glad it worked & sorry for the confusion [img]/images/graemlins/crazy.gif[/img]
    Rajkumar

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:15 PM.

Copyright BetaSoft Inc.