I want my modPath variables to be from one directory - directory

I want my modPath variables to be from one directory, is the following correct? Using C#. Thank you ^^
private readonly string modPath = #"C:\Users\SusanPeter\Mods";
if (string.IsNullOrEmpty(modPath))
{
MessageBox.Show("Sorry wrong directory");
return;
}

I am a beginning, learning to Write a program to check whether this particular Path (C:\Users\SusanPeter\Mods) is valid, and as long as not empty.
If this program is not placed in (C:\Users\SusanPeter\Mods), it will prompt for a message. I am sort of ensuring the path is correct before starting the program.

Related

Checking folder is exist or not in QT

I am learning/looking QT. When I want to reach a folder or file, it is exist or not, program always return folder is not exist (NO).
QDir myDir("D:\try"); //I created try folder under D disk.
if (myDir.exists())
{
qDebug("YES");
}
else
{
qDebug("NO");
}
The '\t' in "D:\try" is interpreted as a tab character by the compiler. And the path "D: try" presumably does not exist.
It's often useful in these kind of tests to print out the string you are using in the debug statement, rather than just the success/fail message, so you can validate that the input is actually what you expect.

SilverStripe 4.1 Email->addAttachment()?

I have a contact form that accepts a file input, I'd like to attach the file to the email that gets sent from the form.
Looking at the API reference isn't really helping, it states that the function expects a filepath with no clarification on anything beyond that.
The submit action will save a record of the into the database and this works correctly, something like:
$submission = MyDataObject::create();
$form->saveInto($submission);
$submission->write();
an Email object then gets created and sent. Both of these are functioning and working as expected.
Trying to attach the File I've tried:
$email->addAttachemnt($submission->MyFile()->Link());
which is the closest I can get to getting a filepath for the document. Dumping and pasting the resulting filepath being output by that call will download the form but that line throws an error and can't seem to locate the file.
I suspect that I'm misunderstanding what's supposed to be given to the function, clarification would be very much appreciated.
P.S. I don't currently have access to the code, I'm looking for some clarification on the function itself not an exact answer :).
In SilverStripe 4 the assets are abstracted away, so you can't guarantee that the file exists on your webserver. It generally will, but it could equally exist on a CDN somewhere for example.
When you handle files in SilverStripe 4 you should always use the contents of the file and whatever other metadata you have available, rather than relying on filesystem calls to load it.
This is how the silverstripe/userforms module attaches files to emails:
/** #var SilverStripe\Control\Email\Email $email */
$email->addAttachmentFromData(
$file->getString(), // stream of file contents
$file->getFilename(), // original filename
$file->getMimeType() // mime type
);
I would try $email->addAttachment($submission->MyFile()->Filename); If it doesn't work, you may need to prepend $_SERVER['DOCUMENT_ROOT'] to the filename.
$email->addAttachment($_SERVER['DOCUMENT_ROOT'] . $submission->MyFile()->Filename);

Max execution work-around Google App Script

I'm looking to retrieve the entire folder/subfolder directory from MyDrive and print out to a file type (not sure what' possible). I ran the following code and received a "max execution timeout" error.
// Log the name of every folder in the user's Drive.
var folders = DriveApp.getFolders();
while (folders.hasNext()) {
var folder = folders.next();
Logger.log(folder.getName());
}
MyDrive contains over 20,000 files, not sure on the folder/sub-folder count. I'm assuming the above code is meant as a starting point and not the actual full script.
Any help would be appreciated to help me get around this issue. I only need to run the script once.
Thanks,
Ryan.

How do I recognize a symlink in Dart when dealing with the Directory class?

When I instantiate a Directory in Dart, and that file exists, how can I check whether the Directory is a real folder, or just a symlink?
The way you can recognize a symlink is if the path differs from the full path. Directory doesn't have fullPath() or fullPathSync(), but File.fullPathSync() works on directories. So you can do this:
bool maybeIsSymlink(String path) {
var fullPath = new File(path).fullPathSync();
return path != fullPath;
}
However this only works correctly when path is absolute, and none of its ancestors are symlinks. To work around that you can get the full path of the directory's parent, append the directory name and compare that:
bool isSymlink(String pathString) {
var path = new Path(path);
var parentPath = path.directoryPath;
var fullParentPath = new File.fromPath(parentPath).fullPathSync();
var expectedPath = new Path(fullParentPath).append(path.filename).toString();
var fullPath = new File.fromPath(path).fullPathSync();
return fullPath != expectedPath;
}
Note that I have not tested this, but I've dealt with symlinks a lot in Dart, and this should work. If pathString ends in '/' you'll have to remove it. I usually end up getting paths from a directory listing, so I track the expected path as I recurse down the directory structure.
You can see a special listDirectory() implementation that detects symlinks and sends Symlink instances to the stream along with Files and Directorys in a branch in buildtool: https://github.com/dart-lang/buildtool/blob/m4/lib/src/util/io.dart
In bleeding edge, there now is a static FileSystemEntity.isLinkSync(path) methods that will tell you if something is a symlink; also when it is a broken symlink.
http://api.dartlang.org/docs/bleeding_edge/dart_io/FileSystemEntity.html
For operations on links we are adding a Link class. The code is out for review now:
https://codereview.chromium.org/12691002
If you want to check from the command line to verify what is happening,
ls -al DIRNAME and check for 'l' in the permissions section, and examine what it's pointing "to" on the right side of the output.
see also man 1 stat
If you're wanting to check that from within Dart itself, I don't know how.
FileSystemEntity.typeSync(path)
return an FileSystemEntityType with one of the values
FileSystemEntityType.DIRECTORY
FileSystemEntityType.FILE
FileSystemEntityType.LINK
FileSystemEntityType.NOT_FOUND

browseForOpenMultiple - crashing

I am trying to work with browseForOpenMultiple function inside Flex, sdk 3.5, I am trying to figure out a bug. The browseForOpenMultiple does not crash everytime, but it seems as though I can upload a file once, but when I go to upload a second file, it crashes when the browseForOpenMultiple function is called. Anyone have any ideas about possible causes?
Update:
private function browseForFiles():void
{
fileBrowser = new File();
fileBrowser.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
fileBrowser.addEventListener(Event.CANCEL, fileSelectionCancelled);
fileBrowser.browseForOpenMultiple("Select Desired Media File(s)", [(mode == "Media")? MediaTypes.getFileFilter() : MediaTypes.getVideoFilter()]);
}
So the code in our array of file extensions was crashing when there were over 60 items listed in an array that gets converted into a string for the FileFilter. This may not be an Adobe limit, but I wanted to make mention that the crash is fixed, so that others who may be encountering issues with browseForOpenMultiple will know what the issue was for this problem. This is not code that I originally wrote, so I will check into it for more clues, but for the time being, too many array items being joined together into a string for FileFilter object caused the crash.
It could be how it's construct the File, without a real file reference.
Try something like this :
var fileBrowser = File.desktopDirectory

Resources