Firefox Add-on save to desktop - firefox

I'm trying to save a file in a folder other than the extensions folder. Right now I'm using:
var file = Components.classes["#mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile);
if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create
file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
}
this.f = file.path+"\\text.txt";
How can I change the file path so that it saves it somewhere else on the machine? Or is this not possible?
Thanks!

You can use different "special folder" keys too. For a list of some common ones, see:
https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Getting_special_files
You can also initialize a file with any absolute path. See:
https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Creating_an_.0ansIFile.0a_object_%28.22opening.22_files%29

Related

Setting the location of Wakatime config files in Portable VS Code

When you set up Wakatime on Portable Visual Studio Code, it automatically puts the config files (.wakatime.cfg, .wakatime.db, .wakatime.log) in C:/Users/<username>. I would like these to be set in the data directory of the VS Code. When you start the VS Code in another computer, it prompts for Wakatime API key because the key was left in the other machine. How can this be accomplished?
In Wakatime's extension.js, this is explicitly specified in line 193 and 689 . I edited the second function to set the config files in data/extensions inside VS Code portable directory but would obviously be overwritten with updates. I just have to change it back after an update. Updates are less often than moving between machines so it will do for now.
getWakaHome() {
let home = process.env.WAKATIME_HOME;
if (home) {
return home;
}
else {
return this.getUserHomeDir();
}
}
getUserHomeDir() {
return process.env[Dependencies.isWindows() ? 'USERPROFILE' : 'HOME'] || '';
}
change above to getUserHomeDir()
getUserHomeDir() {
return 'data/extensions-data';
}
You can set an environment variable to specify where the wakatime files will be stored. Save this variable as $WAKATIME_HOME. It worked on Linux.
Click here to see more.

How to copy more than 5k files with FTP client from linux server

i need to backup a site's FTP. The site is hosted on a linux server. The problem is that there is a folder with more than 5k files. Linux can't show me more than 4998 files, so i cant copy these files 'cause the server don't give me more than 4998.
I can't delete these files to see the others 'cause the site is actually online. I can't move these file in another directory for the same reason.
What can i do? i'm trying using a shell...but i don't know...i'm not sure using this method.
I got solution for my own answer
<?php
$rootPath = realpath('wp-content/uploads/2014/07');
// Initialize archive object
$zip = new ZipArchive();
$zip->open('dio.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** #var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
You can do this through the command line, this guide shows you how. It seems mget (the ftp command) isn't recommended for recursive calls (subfolders and their content), so wget can also be used, se this.
I also like to zip such folders with many files into one, for easy oversight when up-and-downloading. Use
zip -r myfiles.zip myfiles
Here's a guide for that too.

Programmatically create shortcuts for folders in Windows

I have a folder A and a folder B. For each subfolder inside A I need to check if B contains a link to that subfolder. If not, I need to create it.
I'm currently creating the links using the code found on this page: Creating a file shortcut (.lnk)
My problem is that this code always creates a file shortcut, not a folder shortcut, so if I try to open the shortcut it does not open the corresponding folder. Anyone knows how to create folder shortcuts instead?
I'll answer my own question because I found lots of people asking this on the web and nobody providing an answer.
I found through trial and error that if you use the Path.GetFullPath method to calculate the value to assign to the TargetPath property, the output is in a format that's recognized as a folder path, so the system will automatically identify it as a folder shortcut and assign the corresponding icon.
FileSelectFolder, directory
if (directory != ""){
Loop, %directory%*.*, 1, 1
{
if (FileExist(A_LoopFileFullPath) = "D")
FileCreateDir, % A_Desktop "\myShortcuts" SubStr(A_LoopFileFullPath, StrLen(directory) + 1)
else
FileCreateShortcut, %A_LoopFileFullPath%, % A_Desktop "\myShortcuts" SubStr(A_LoopFileFullPath, StrLen(directory) + 1) A_LoopFileName ".lnk"
}
Run, % A_Desktop "\myShortcuts"
}
Esc::ExitApp

Retrieve StorageFile with the help of path from Local Folder

I am making Windows 8.1 Universal App and want to retrieve file,
(local -> folder -> sub Folder -> file) which is stored in Local Folder.
One way is open Local Folder, then open folder, then open sub folder, then file.
But If I know the path, can I simply open the file?
(Like in Windows Phone 8, store.OpenFile())
Is there an API which would return Storage File when passed path?
Example: GetStorageFile("local/folder/subFolder/file") ?
You can use StorageFile.GetFileFromApplicationUriAsync and pass in a URI such as ms-appdata:///local/folder/subfolder/file.txt. This is preferred over GetFileFromPathAsync (#Parad1s3's suggestion) since it is relative to your data folder and won't change if the location of the app changes (eg, on a phone the user can move to or from the SD card).
string path = ApplicationData.Current.LocalFolder + "\\" + "YourFolder" + "\\" + "YourSubfolder" + "\\yourfile.xml";
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile file = await folder.GetFileAsync(path);
Hope this helps.

How to check with WINAPI file path is disk or file or directory?

How to check with WINAPI file path is disk or file or directory?
Use GetFileAttributes.
Edit: You can also check SHGetFileInfo
Could try FindFirstFile:
http://msdn.microsoft.com/en-us/library/aa364418%28v=VS.85%29.aspx
Once you have the find data (passed as the 2nd argument to that function):
if(result->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//file is a directory
}
else
{
//file is not a directory
}
Also, to see if something is a volume, could try something like:
if(result->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
{
if(result->dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT)
{
//path is a volume; try using GetVolumeNameForVolumeMountPoint for info
}
}
HTH
See if the path has a drive letter in front of it? All UNC's take the form "\\server\share\file_path" No drive letter.
Out of curiousity I looked this up. Based on this MSDN article Naming Files, Paths, and Namespaces, it seems my advice is exactly how it says it should be done.

Resources