I have a command that does the download of the file and saves it in the folder, now to get faster the dowload I want to make it download the zipped file, so the file decreases the size and the dowload will be faster, somebody knows some way for me do that ?
At the moment I use the following command to download
XDocument rss = System.Xml.Linq.XDocument.Load("http://pox.globo.com/rss/g1/mg/sul-de-minas/");
var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var filename = Path.Combine(path, "rss.xml");
rss.Save(filename);
Related
I have been using QTTabBar for a while and am using .js scripts with it. The scripts are run using Windows Script Host, but I find myself having to specify hardcoded directories in the .js file instead of relative paths. This is not ideal.
In the .js file, is it possible to get the containing folder of the .js file (no matter what directory it is originally run from)? I just need to avoid specifying absolute paths somehow. For example, part of my .js file might look like this:
var qs = new ActiveXObject( "QTTabBarLib.Scripting" );
var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtFile = fso.OpenTextFile("C:\\Installation\\Scripts\\QTTabBar\\dirs.txt", 1, false, 0);
var fText = txtFile.ReadAll();
I can't just put "dirs.txt" in the OpenTextFile function because when the .js script is run in QTTabBar, the working directory (I think) starts in system32 rather than at the .js file location. So I somehow need to get the path of the .js file itself and combine it with the relative name to create the absolute path. But I'm not sure if this is possible or how to do it.
You can get the path of current JScript file with
js_file_path = WScript.ScriptFullName;
and the absolute path to the text file is
path = WScript.ScriptFullName.split("\\").slice(0, -1).join("\\") + "\\dirs.txt";
No includes or imports are needed if the script is run in Windows Script Host.
Need help to check whether a file has been successfully downloaded or not in a specified folder.
The file name dynamically changes every time a new file is downloaded but the initial part of the file "Pivot_Report" always stays the same
The actual file gets downloaded in the mentioned folder but protractor is not able to find it with just the initial part of the full name
This is the code I'm using (filenamePath is '/Users/Shubh/Documents/')
browser.driver.wait(function() {
var fileName = filenamePath+"*.csv"
var filesArray = glob.sync(fileName)
if (typeof filesArray !== 'undefined' && filesArray.length > 0){
return filesArray
}
}, 10000).then(function(filesArray) {
var fileWithPath = filesArray[0]
var temp = fileWithPath.indexOf("Pivot_Report")
expect(fileWithPath.indexOf("Pivot_Report") >= 0).toBe(true,'Pivot Download is not succesfull')
if(fs1.existsSync(fileWithPath)){
fs1.unlinkSync(fileWithPath)
}
})
Getting the timeout error
It happens, because your path is incorrect.
I think easiest way is to use path.resolve() :
var path = require("path");
var filenamePath = path.resolve("Users/Shubh/Documents");
and then you will have (notice that you missed a / before *.csv)
var fileName = filenamePath+"/*.csv"
I have an IDML file that I unzipped. I now want to compress the expanded folder back into an IDML file. I have access to a Mac or Linux machine.
What are the ways I can do this?
Zipping the file using zip (command line) or with Keka, BetterZip or Archive Utility don't work. InDesign issues the error:
Cannot open the file. Adobe InDesign may not support the file format, a plug-in that supports the file format may be missing, or the file may be open in another application.
The problem with regular zip is that the zip archive contains a “mimetype” file that shouldn’t be compressed if you want InDesign to identify the newly-created IDML. So the way you have to re-zip the file (and the way the ePub scripts work) is like this:
They first create a zip archive which contains only the mimetype file, uncompressed. zip -X0 'myfile.idml' mimetype
Then they add the rest of the files/folders into the zip archive, this time with full compression. zip -rDX9 "myfile.idml" * -x "*.DS_Store" -x mimetype
In shell script terms, the ePub scripts do this (assuming the current directory is the one containing all the IDML contents):
zip -X0 'myfile.idml' mimetype # create the zip archive 'myfile.idml', containing only the 'mimetype' file with no compression
zip -rDX9 "myfile.idml" * -x "*.DS_Store" -x mimetype # add everything else to the ‘myfile.idml’ archive, EXCEPT .DS_Store files and the ‘mimetype’ file (which is already there from the previous step)
To save you time reading the zip man page, here’s what all these options mean:
-X = “no extra” — do not save extra file attributes like user/group ID for each file
-0 = “compression level zero” — no compression
-r = “recurse paths” — go through everything in the directory, including nested subfolders
-D = “no directory entries” — don’t put special stuff in the zip archive for directories
-9 = “compression level 9 (optimal)”
-x = “exclude these files”
Follow this voodoo, and you should be able to create legal IDML files.
Source: http://indesignsecrets.com/topic/how-do-i-re-zipcompress-an-expanded-idml-file
A big thanks to Chuck Weger and David Blatner at http://indesignsecrets.com
From within InDesign
use this jsx script to expand an IDML
//DESCRIPTION: Expands an IDML file into folder format
ExpandIDML();
function ExpandIDML(){
var fromIDMLFile = File.openDialog("Please Select The IDML File to unpackage");
if(!fromIDMLFile){return}
var fullName = fromIDMLFile.fullName;
fullName = fullName.replace(/\.idml/,"");
var toFolder = new Folder(fullName);
app.unpackageUCF(fromIDMLFile,toFolder);
}
And that one to produce an IDML package:
//DESCRIPTION:Produces an IDML package from the contents of a directory:
CreateIDML();
function CreateIDML(){
var fromFolder = Folder.selectDialog("Please Select The Folder to package as IDML");
if(!fromFolder){return}
var fullName = fromFolder.fullName;
// var name = fromFolder.name;
// var path = fromFolder.path;
var toIDMLFile = new File(fullName+".idml");
app.packageUCF(fromFolder,toIDMLFile);
}
I'm attempting to download files from a website that uses a CDN for distribution. The URLs on the download page all end with file.pdf but clicking on the link in a browser results in the download of a file with a descriptive file name (e.g. 'invoice1234.pdf'). Obviously parsing the URL to get the file name results in every file being named file.pdf - I would like to use the same file name that is used when downloading via the browser. My code looks something like this:
filename = File.basename(download.href)
agent.pluggable_parser.default = Mechanize::Download
agent.get(mov_download_link.href).save("#{path}/#{filename}")
agent.pluggable_parser.default = Mechanize::File
Any ideas would be appreciated!
That filename is probably in a header that looks like this:
{'content-disposition' => 'filename="invoice1234.pdf"'}
If so:
f = agent.get(mov_download_link.href)
filename = f.header['content-disposition'][/"(.*)"/, 1]
f.save("#{path}/#{filename}")
I'm downloading zip files and place them in isolated storage on Windows Phone 7. Is there an API or library that allows me to unzip the files?
You can use SharpZipLib to decompress downloaded zip files. I have used this version (binaries downloaded from Codeplex) in my applications without any issues, however, I would recommend download the source and compiling it yourself. The decompressed file can be read into a string -
// check for magic numbers
if (data.Length > 2 && (data[0] == 31 && data[1] == 139))
{
using (var ms = new MemoryStream(data))
using (var gzip = new GZipInputStream(ms))
using (var reader = new StreamReader(gzip))
{
fileContents = reader.ReadToEnd();
}
}
data is an array of bytes which holds the zip file read from IsolatedStorage. fileContents is a string that holds the contents of the decompressed file.
HTH,
indyfromoz
SharpZipLib is under GNU license and is therefore not allowed by the Microsoft app store.
I found the following small library useful for unzipping files on WP7:
REALLY small unzip utility for Silverlight – Part 2