What directories are there other than the temp folder(in appdata)? - uac

Are there directories other than appdata that I can drop files to without UAC privileges?Or is the AppData place the only location?

Users can write to anywhere in their profile. E.g.:
SHGetFolderPath(CSIDL_DESKTOPDIRECTORY) e.g. C:\Users\User0\Desktop
SHGetFolderPath(CSIDL_MYDOCUMENTS) e.g. C:\Users\User0\Documents
SHGetFolderPath(CSIDL_APPDATA) e.g. C:\Users\User0\AppData
SHGetFolderPath(CSIDL_LOCAL_APPDATA) e.g. C:\Users\User0\AppData\Local
As well as the Common AppData folder:
SHGetFolderPath(CSIDL_COMMON_APPDATA) e.g. C:\ProgramData

Related

Batch: How to run tree command from current directory?

I may be confusing current directory with working directory but regardless I am trying to make a batch file that runs the tree command from the folder it's currently in.
I have a folder called "Network_Switch_Backup" with a script, some other items and a subfolder called "backups".
This has worked for testing purposes:
tree U:\Desktop\Network_Switch_Backup\backups /f
But as I will be zipping it and sending it to different computers and users clearly this isn't practical since they could put the folder anywhere besides the desktop.
I've looked at other threads and amongst other things I tried, this looked the most promising (but still did not work):
tree %cd%\backups /f
However tree %cd%\downloads /f works perfectly fine when running from cmd so I'm just a bit confused.
It is advisable in batch files to reference executables to run with full qualified file name which means full path + file name + file extension, especially if the storage location of the executable is well known. That makes the batch file independent on the values of the environment variables PATHEXT and PATH. PATH is quite too often not correct defined on many computers running Windows.
The full qualified name of TREE is %SystemRoot%\System32\tree.com.
Environment variable SystemRoot is not defined as system or user environment variable like PATH and PATHEXT, but is nevertheless defined on execution of a batch file. So it is very safe to use this Windows environment variable.
What is the reason for '...' is not recognized as an internal or external command, operable program or batch file? explains very detailed how Windows command processor finds executables and scripts not specified with full qualified file name on command prompt or in a batch file.
There are two directories which need to be taken into account on coding an application or script:
The application/script directory is the directory containing the program or script.
The current directory or working directory is the directory from which the program or script is executed.
For example a batch file is stored in directory "%UserProfile%\Desktop". Windows sets the directory of the batch file as current directory on simply double clicking the batch file on user's desktop. Therefore the script directory is the current directory on execution of the batch file. But if this batch file is executed by right clicking on the batch file and left clicking on context menu option Run as administrator, the batch file stored in "%UserProfile%\Desktop" is usually executed from directory %SystemRoot%\System32 depending on user account permissions and on user account control setting of current user. The reason for making %SystemRoot%\System32 the current directory before executing the batch file is explained in detail by answer on Why does 'Run as administrator' changes (sometimes) batch file's current directory?
The MSDN article Naming Files, Paths, and Namespaces explains in detail how to reference files and folders relative to current directory. The current directory is simply not included in file/folder argument string or alternatively represented by .\.
In case of drive and path of current directory needs to be known, for example to output it on running a batch file, there is the dynamic environment variable CD (short for Current Directory). %CD% or !CD! with delayed expansion enabled expands to full path of current directory which does not end with a backslash, except the current directory is the root directory of a drive. The help output on running in a command prompt window set /? explains dynamic environment variable CD briefly on last help page.
Batch files need to be designed very often to reference files or folders with a path relative to directory of the batch file. In this case it is not advisable to use the current directory because the current directory can be really any directory.
The help output on running call /? in a command prompt window explains how arguments of a batch file can be referenced from within a batch file. Argument 0 is always the batch file itself.
%~dp0 references drive and path of the batch file. This file path ends always with a backslash, but of course can contain a space or one of these characters &()[]{}^=;!'+,`~ which require entire file/folder argument string to be enclosed in double quotes. So %~dp0 must be concatenated in a batch file without an additional backslash after that string and the entire argument string must be enclosed in double quotes to work safely.
So the command line to use to reference the subdirectory Backups in directory of the batch file independent on which directory is the current directory is:
%SystemRoot%\System32\tree.com "%~dp0Backups" /F
A bug of cmd.exe explained in detail on What is the reason for batch file path referenced with %~dp0 sometimes changes on changing directory? should be taken into account on using %~dp0 in a batch file.

Check if file exists in 2 directories, delete files that aren't in both directories

So, I'm programming a game, but the compiler I use is written as a Windows batch file. I'm using Windows 10 as my operating system.
In my game files, I have one folder with images, and another folder with upscaled versions of those images that have the same file name and extension.
What I want to do is have the batch file go through all the images in the directory with the upscaled images, and check if a file with the same name and extension exists in the directory with the original images. If it doesn't exist in the original directory, it will delete it from the upscaled directory.
I got it working using an answer over here:
Batch Extract path and filename from a variable
All I had to do was extract the file name and extension, and then run all the files in one folder through the loop, checking if the file exists in the other folder.
Here is my code:
for %%i in (%folder1%\*.png) DO (
if not exist "%folder2%\%%~nxi" ECHO %%~nxi
)
If you actually want to delete the files, change ECHO to del /q, be warned you will lose files, so make sure you have backups.

rename a file using C function rename()

I'm using a Mac. I need to rename a file in the /Library/Application Support/AppName/filename.aiff
This is the system library and not /User/username/Library...
I'm using the rename(old name, new name) function. This function doesn't work (even though it doesn't return an error) if I place the file in the /Library/Application Support/AppName directory but it works properly if I place the file, for example, in /User/username/Documents/filename.aiff.
I don't know what the problem is. Any help would be appreciated. Thanks!
You don't own the directory you're trying to move files into:
/Users/Username/... is a user owned directory, so you're allowed to manipulate files there.
/Library is not a user owned directory.
In order to manipulate files in a non-user owned directory you would need elevated permissions. Instead of using /Library you should be using ~/Library, which is the user owned directory. ~/Library is the shorthand name for /Users/Username/Library.
If the rename is working fine in other path means the problem should be related to permission to access file or with the path searched for file.

Find trashed file location in GIO

The documentation says that all files moved to trash are stored normally in ~/.local/share/Trash/files. Are there an exception for files removed from removable media? Are they stored in drive_root/.Trash-xxx directory? Or is this behavior obsolete?
How do I find real file path of file in trash can? I have a list of GFileInfo obtained from g_file_enumerate_children for trash:/// uri. It's easy if all files are stored in one directory. But I'm afraid this could be different for removable drives.
From removeable media there are the .Trash-$(user_id) folders, so you will have to get all mounted disks as well as the home trashcan.
Under each mounted device (not being the home folder) will be a .Trash folder for each user ever having something deleted. So e.g. for my user foo which has ID 1000 (see /etc/passwd) you will have to look for .Trash-1000 folders.
This is AFAIK not obsolete, just think about the oposite, the file would have to be copied over to your home storage just to move it to trash...
For the second part, you probably better off asking that on the glib/gtk mailinglist.

Command Prompt and batch files

I'm trying to copy a number of files from a directory. I want to include the file path from the base of this particular directory tree, however, I only have a list of the file names to go by. Is there a way to copy either:
a list of files with their directories appended to the beginning in a .txt file
a copy of the folders in the directory with copies of the files placed in their original places in the original directory.
Each file in the directory has a unique name.
I've looked all over google, but the closest I've found is xcopy, which I don't believe is capable of this.
Thanks!
For the second option you can use xcopy /s or robocopy /s. Both are great tools for this kind of job.

Resources