Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 369 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy folder contents to a created .zip file: 'file not found or no read permissions'

#1
I'm trying to create a .zip file from an existing folder using JScript and it seems that my copyHere function is not copying to the .zip folder. Instead I get a popup box titled 'Compressed (zipped) Folder Error' with the message 'file not found or no read permissions' even though I have read/write privileges on the file according to the value of my file.attributes property (32).

Here is the script I'm using:

<!-- language: lang-js -->

//Get commman line arguments
var objArgs = WScript.Arguments;
var zipPath = objArgs(0);
var sourcePath = objArgs(1);

//Create empty ZIP file and open for adding
var fso = new ActiveXObject("Scripting.FileSystemObject");

var file = fso.CreateTextFile(zipPath, true);
// Create twenty-two byte "fingerprint" for .zip
file.write("PK");
file.write(String.fromCharCode(5));
file.write(String.fromCharCode(6));
file.write('\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0');

var objShell = new ActiveXObject("shell.application");
var zipFolder = new Object;

zipFolder = objShell.NameSpace(zipPath);

sourceItems = objShell.NameSpace(sourcePath).items();

if (zipFolder != null)
{
zipFolder.CopyHere(sourceItems);
WScript.Sleep(1000);
}

Now the CopyHere function works for copying the contents of the sourcePath to a normal folder but when I try to create a .zip file and copy the contents to that, nothing happens. Any ideas on why copyHere is not copying the contents of the sourcePath to the .zip?

**An Example** for calling this script would be:

`cscript win-zip.js C:\desired\zip\file.zip C:\path\to\source\folder`

And the **desired outcome** would be that file.zip was created and now contains the contents of the source folder. Could this be a problem with permissions? What might cause this behavior?

___

**Side Note**, using a vbScript and the same commands I can successfully create and populate a .zip, so why doesn't it work using jscript!

<!-- language: lang-vbs -->

Set objArgs = WScript.Arguments
ZipFile = objArgs(0)
SourceFolder = objArgs(1)

' Create empty ZIP file and open for adding
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)

' Get items in source folder
Set sourceItems = CreateObject("Shell.Application").NameSpace(SourceFolder).Items

' Add all files/directories to the .zip file
zip.CopyHere(sourceItems)
WScript.Sleep 1000 'Wait for items to be copied


___

Any *helpful* comments are greatly appreciated, thanks!
Reply

#2
As Raymond said, the problem was that I had an open reference to the .zip folder in the `file` variable that I created (which had a lock on the folder so I could not copy any contents to it). **The solution** is to call

`file.Close();`

after writing to the file, that way we can access the file to copy contents to it :)
Reply

#3
I encountered the same problem (file not found or no read permissions' even though I have read/write privileges on the file according to the value of my file.attributes property).
The problem disapeared as soon as I found and suppress a 0 length file somewhere in the directory to be copied with the copyhere method.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through