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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy file

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
US
Hi all!

I would like to copy a file from one dir to another, in javascript, just as the FileSystem object in asp, any ideas?

thanxs,
alej
 
alej,

The FileSystemObject and or shell object can be used to do this client-side, but:

1) Only in IE, and
2) Only if running activeX objects is OK with your target audience.

If both of those are fine, then check out the FSO pages on the MSDN site:


Hope this helps!

Dan
 
Thanxs, its enough for my requirements! I thought you can't use this object client side.

cheers,
alej
 
Its me again. I got the function but now I have some troubles defining the path to a remote computer: 'path not found'. This is what I try:

fso.CopyFile ("c:\sample.txt","\\172.17.17.109\\c$\\MOA_Data\\",true);

Any syntax error? I also tried using drives but had no success. Thanxs!

cheers,
alej
 

You need to double up your '\' characters everywhere. Try this:

Code:
fso.CopyFile ("c:\\sample.txt","\\\\172.17.17.109\\c$\\MOA_Data\\",true);

Also make sure the the destination path exists ;o)

Dan
 
Oh yessssssssssssss!! thanxs a lot, looks like i am on the moon!

cheers,
alej
 
This is really strange! The command above was working, but now I get 'permission denied' when I try to run it. I did not change any permissions in the PCs! Any ideas??? thanxs.

cheers,
alej
 
Yes and yes. And while I dont press ok to the error message I can see my user in the 'Shared sessions' in the server.

alej
 
Hi again!

I discovered what caused my error, I was changing the path and then I forgot all the time the ending back slash, and this created a 'permission denied' error instead of a 'path not found' :-S

cheers,
alej
 
To copy a file from one directory to another, is it neccessary to include IP address, computer name etc. I ahve tried all over the net and am finding nothing. I need a simple script that will constantly run checking a folder for a file and if it is there copying it to two different destinations.
 
H\I keep getting the Active X pop-up requesting if I wish to run the ActiveX component. But as I want this to be automated I need something to stop this window from popping up. I have tried to disable all security, not a good idea, but it still happens. I have included the code below. Is there an easier way around this issue?

<html>
<head>File copy in progress...Don't close this page.</head>
<SCRIPT LANGUAGE="JavaScript">

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:15"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
//-->


<!--
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
file = myActiveXObject.GetFile("c:\\test\\test.txt");
file.copy("c:\\test1\\meantimes.txt", true);
file.copy("c:\\test2\\meantimes.txt", true);
// -->
</SCRIPT>
</html>
 
Waidesworld,

Imagine a website that copies a thousand viruses onto your computer when you view it, without any warning.......

Of course that box pops up every time that you try to copy something to the user's machine. You can't automate this process because it would be a hackers dream to copy something onto a user's machine that easily.

-kaht

banghead.gif
 
But basically I just want a script to run this locally. I thought a botch job like this could do the trick but alas my script writing skills lack and this was the best effort I had. Any help would be appreciated.
THis is never going to be a web page just a method of generating a script.
 
but it should work if you allow to run ActiveX in the internet explorer's security settings.
 
Aaah but it doesn't and this is my issue. I have "enabled" all the ActiveX components, and any ones that were on "prompt" are now "enable", but it is still cropping up. I can't add it as a trusted site as it won't accept the file location C:\....\fileshare.html because it is not starting with http or ftp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top