Accessing files using Racket - scheme

I want to make a DrRacket program that can copy all of the files from a given directory (taking it off of a USB Camera (when it's plugged in it's seen as a mass storage device)) and paste them into a folder on my computer's hard drive. For whatever reason I'm unable to figure out DrRacket's implementation of a path on the computer (ie. for the Desktop on a Windows Machine it would be: C:\Users\Mike\Desktop) I read the help desk and still can't figure this out. Any suggestions as to where I should look to clear up my confusion? I think the function call that I'll need to implement this idea is:
(copy-directory/files src dst)
After I figure that out I'm going to work on a GUI for it so it operates at the click of a button.

You may be looking for the content about paths. You can create a path using build-path. A lot of the path-manipulating functions, though, can take strings as well. So you should be able to say something like:
#lang racket
(copy-directory/files "C:\\Users\\Mike\\Desktop\\..." ...)
with the ... replaced appropriately.

Related

Need help understanding a move script written for CMD involving multiple subdirectories into one directory

I got a folder with a lot of images in it, and I'd like to move everything to the main folder so basically I would like to turn this:
L:\Pixiv\Tags\44324\Image1.jpg
L:\Pixiv\Tags\4564356\Image2.jpg
L:\Pixiv\Tags\325423\Image3.jpg
L:\Pixiv\Tags\16324\Image4.jpg
...into this
L:\Pixiv\Tags\Image1.jpg
L:\Pixiv\Tags\Image2.jpg
L:\Pixiv\Tags\Image3.jpg
L:\Pixiv\Tags\Image4.jpg
I did some looking, and I discovered a move function for CMD, and while most of it I can understand, some of it I can't, and frankly, I'm just that smart enough to know what happens when you start playing around with stuff you don't fully understand, so I don't do it. Point is your basic move function is basically something like "move c:\Whatever C:\Whocares," but as you can tell from below, this is a little more complicated.
for /r %d in (*) do move "%d" "d:\all snaps\"
/r I think goes through all the folders at the current target directory. So if I'm in L:\Pixiv\Artists and I type in this code for L:\Pixiv\Artists as a destination folder every file in Artists is going to be dumped into Tags. Is this correct?
%d I couldn't make sense out of, so I've no idea what it does. Also, for ease of use, I would like to put this in a batch script, because boy howdy, do I got a lot of folders that needs to be fixed. From what little I was able to read I should write the same as above, but change %d to %dd, correct? Also where at would I add a target directory, so I could just write a batch script, and be done with it? Also, apologies in advance for my lack of knowledge, usually I use Batchrun when it comes to automating stuff.

Porting MATLAB code from Windows to Mac

I have just switched from a PC to a Mac, and I am finding that lots of my MATLAB code previously written when I had a PC does not work on my Mac! I have been working on MATLAB for a while now, but I am not an expert yet.
After searching around for differences between PC and Mac, I noted that a few things indeed differed, but I'd love to hear about whether I need to go through all my yet written MATLAB code and update it manually to make it work on my Mac.
Please let me know what best to do here.
Example:
clear all
cd 'c:\users\sss\Desktop\MATLAB\project\DataFile\'
load data
cd ..
Why doesn't this work? Is it because of the backslash required for MATLAB on a Mac?
Of course, if you try to access a Windows-style path on a Mac, it will error.
MATLAB includes a set of functions that make it fairly easy to make your code cross-platform with respect to these sorts of issues. Take a look at, for example, the functions fullfile, fileparts, filesep, pathsep, ispc, and ismac.
I'm afraid that for the moment, you'll probably need to recode things to be either Mac-specific or to be cross-platform using the functions above.
One way is to have a path variables or variables set which determine where your data is held. You can even use computer or ismac and ispc to automatically switch to the correct version:
if ispc
dpath = 'c:\users\sss\Desktop\MATLAB\project\DataFile\';
elseif ismac
dpath = '/Users/sss/MATLAB/project/DataFile/';
end
load (fullfile(dpath, 'data.mat'));
If you have multiple files in subdirectories of /MATLAB/project/, you can set a project directory (similarly to matlabroot but pointing at where your files for that project are kept), and then use fullfile to select the correct subdirectory.
e.g. given a directory in proot that points to wherever /MATLAB/project/ is on the appropriate computer, these produce filenames which are in /MATLAB/project/data and MATLAB/project/output respectively:
datain = fullfile(proot, 'data','data.mat');
dataout = fullfile(proot,'output','output.mat');

Assigning my own file path in reverse engineering

I am working on reverse engineering and i wanted to give my own file path without using open dialog box like writing a fixed file path and read a file from that every time the software start.i tried to give the file name in a .data section of the software but it retrieve only the hex number not the string.
Is there any way hooking windows API for file open?or any way to write in memory and to read it every time the software starts?Any advice or direction would be greatly appreciated.
I think that what you may be looking for is "intercepting system call", quick google search came up with this link:
http://jbremer.org/intercepting-system-calls-on-x86_64-windows/ so it should be possible and not too difficult.
Basically if you manage to intercept a call to GetOpenFileName and replace it with custom implementation you should be able to do what you want (that is put hardcoded file path to appropriate buffer in LPOPENFILENAME structure)
As for your attempt to modify compiled code (I assume that what you are referring as reverse engineering is disassembling and modifying binaries) it should be possible to do, but it will require deep knowledge of windows binary architecture and assembly language.

Getting safe temp folder in Windows

I need to get a safe temp folder where I could store temporary files for my application, but so far my research has lead me to conclusion that all approaches I've found are flawed.
The first idea was to use GetTempPath function, but that causes two problems:
The folder might not exist, so I would have to truncate folders one by one up to root, and recreate them if they do not exist back to full path (error prone, tedious)
From "Larry Osterman's WebLog" click it seems that GetTempPath might fallback to USERPROFILE or Windows directory and extract whole lot of files right in there, which is SUPER BAD(TM)!
In the same post, there is a suggestion to use GetEnvironmentVariable, but this seems a dangerous function to me (missing TMP & TEMP envvars for instance).
Is there a cleaner function I could use? Seems that SHGetKnownFolderPath has no clue what temp folder is.
Your program is probably not the only one to rely on GetTempPath, so it's reasonable to expect it to return a proper writable path. Especially since Windows automatically initializes the TMP and TEMP environment variables for you; someone would have to go to some trouble to override them, and it would be their responsibility to make sure the change did not mess up their system.
I would go ahead and assume GetTempPath works properly, and worry about failures when you try to create the temporary file - there are other errors that might occur at that time that you need to check for anyway.
An idea would be to get the path where your application is (GetModuleFileNameEx combined with GetModuleHandle(NULL) and GetCurrentProcess) since this directory cannot be deleted under windows as long as your application is running from it (maybe I'm wrong ...some years ago I couldn't do this :) ) and in this directory create a temporary directory.
Your first bullet point is the solution. Wrap it up in a method so that you don't duplicate code.
According to this answer, Boost's Filesystem library can be used for this.

Visual Studios: Getting standard font... files?

I've run into another problem while fixing up my game to use this library.
SDL.NET, the library I'm using for graphics and input in my VB.NET app, has its own special Font class which is entirely separate from System.Drawing.Font. Here are its two constructors:
public Font(string fileName, int pointSize)
public Font(byte[] array, int pointSize)
Both need a file, in glaring contrast to System.Drawing.Font (which just needs the font family name). I'm not sure where these files are. My first instinct was to look in Windows\Fonts for the ones I want to use, but... you can guess how that approach failed.
I need to find the files for Cambria, DotumChe, and Photo (all of which came installed on the computer). My program is very far from completion, so I'm not worrying about the legal complications of what I'm trying to do. I just want to find the files and get them in my project so I can move on. Is there a place on my computer where I can find them?
A C# example is available at Steve's Tech Talk. It uses P/Invoke to get the fonts folder path.
I'm assuming you plan on resolving legal/licensing issues before distributing the game.

Resources