On Windows 10 I am trying to create a soft link to a file through command prompt opened as an Administrator.
mklink "E:\Folder A\Folder B" "E:\Folder A\Folder C\bibliography.bib"
...where I want to create a soft link to bibliography.bib file into a folder B.
This throws me an error Access denied
What could be the reason?
Had to modify my command to
mklink "E:\Folder A\Folder B\bibliography.bib" "E:\Folder A\Folder C\bibliography.bib"
first of all we can create symbolic link from empty directory to file or visa versa - from empty file to directory via FSCTL_SET_REPARSE_POINT - this is legal and will be work. and we can work with target file (or directory) through this symlink. say in case target is file - we can open and read it as file. but any file browser will be incorrect work with such symlink, because it will be use source file attribute FILE_ATTRIBUTE_DIRECTORY - as result try work with file like with directory or visa versa. because this exist sense use only file -> file or directory -> directory symbolic links (the src and target have the same FILE_ATTRIBUTE_DIRECTORY attribute - both have or not have)
also the mklink assume that symbolic link to be created file - yet not exist. internally it use NtCreateFile with FILE_CREATE disposition. as result we got error, if file already exist. if directory already exist and in call NtCreateFile we not use option FILE_DIRECTORY_FILE (mklink use this option when we use /D switch) - we got STATUS_FILE_IS_A_DIRECTORY error. (The file that was specified as a target is a directory and the caller specified that it could be anything but a directory.). but mklink before display error message, first convert it to win32 error code, and it converted to.. ERROR_ACCESS_DENIED. as result we and view Access denied message, despite the error have nothing common with access denied
if we want create symlink to file via mklink, we need select yet not existing file name(path) as symbolic link to be created
Related
I'd like to rename a directory with the Storage Facade (S3 object). I've tried using move and rename, both with and without trailing slash, none of these work.
Storage::disk('s3')->move($dir_temp, $dir_final);
Storage::disk('s3')->move($dir_temp.'/', $dir_final.'/');
Storage::disk('s3')->rename($dir_temp, $dir_final);
Storage::disk('s3')->rename($dir_temp.'/', $dir_final.'/');
I did use rename function, and it did work for renaming a directory.
This code worked for renaming directory dir 1 to dir 2:
Storage::disk('movies')->rename('dir 1', 'dir 2');
Now, it depends on what error did you get.
make sure, you have rwx rights to the parent directory
make sure the source directory exists, and the destination does not
make sure the name is valid for a name, for example, windows OS will not allow certain characters in the name
make sure you do have permissions to the source directory for that operation
be very carefull with slashes, as windows OS has different path slashes than linux.
For the directory separator, to be platform independent, you can use
$DS = DIRECTORY_SEPARATOR;
Also, the permissions can be quite tricky, as, if you have the app deployed, traditionally, the http user is the user under which all the code is executed, so keep that in mind.
I'm trying to build a service in go that writes to a file with reference to the root directory as opposed to the working directory.
For example, my working directory is /Users/joe/dev/go and I want to create a file test.txt in the directory /Users/joe/generatedFiles/. I want to write a file /Users/joe/generatedFiles/test.txt.
I can't write to this directory unless the folder generatedFiles is created else I get the error "no such file or directory."
To do this I plan on calling os.MkdirAll("Users/joe/generatedFiles/", os.ModePerm) but this isn't giving me the expected functionality. Instead, it creates the folder: /Users/joe/dev/go/Users/joe/generatedFiles/.
I've also tried calling os.MkdirAll("/Users/joe/generatedFiles/", os.ModePerm) with a slash at the beginning of the file path but this is doing nothing. What can I do to write to a file in reference to the root directory?
Use an absolute path to specify the directory:
os.MkdirAll("/Users/joe/generatedFiles/", os.ModePerm)
Note the leading /.
In our inbound directory we have the following file structure.
abc.csv.timestamp
abc.csv.timestamp
abc.csv.timestamp
I want to find the most recent file in the directory and MOVE to another directory.
However i want to pass the file pattern abc.csv.* as a string to the command.
Any pointers ?
I am looking for a way to add File(s) to an existing directory that has a random name as part of a Visual Studio Setup Project and I hoped someone might be able to help me solve this puzzle please.
I have been attempting to obtain the discovered path property of the directory using a Launch Condition; Unfortunately this method returns the full file path including the filename, which cannot be used as a directory property.
The directory in question takes the form [AppDataFolder]Company\Product\aaaaaaaaaaaa\
where aaaaaaaaaaaa is a random installation string.
Within the Launch Condition Setup I check for the directory's existence by searching for a file that would appear inside it,
Search Target Machine
(Name): File marker
Filename: sample.txt
Folder: [AppDataFolder]Company\Product\
Property: DIRFILE
Launch Condition
(Name): File marker exists
Condition: DIRFILE
In the Setup Project I add the file I wish to insert, with the details
Condition: DIRFILE
Folder: 'Installation folder'
Then in File System Setup I add a new folder entry for the random directory aaaaaaaaaaaa
(Name): Installation folder
Condition: DIRFILE
DefaultLocation: [DIRFILE]\..\ *Incorrect*
Property [DIRLOCATION]
As you can see the installer detects the existence of the marker file but, instead of placing my file at the same location, when using [DIRFILE] the installer would incorrectly try and insert it INTO the file;
This is because the file path was returned
[AppDataFolder]Company\Product\aaaaaaaaaaaa\sample.txt
where I instead need the directory path
[AppDataFolder]Company\Product\aaaaaaaaaaaa
Therefore I was wondering if it was possible to return the directory the file was found in from Search Target Machine (as opposed to the file location of the file), if I could extract the directory path by performing a string replace of the filename on the file location DIRFILE within the DefaultLocation field in File System Setup, or if perhaps there is even another method I am missing?
I'm also very interested in a simple solution for this, inside the setup project.
The way I did solve it was to install the files to a temporary location and then copy them to the final location in an AfterInstall event handler. Not a very elegant solution! Since it no longer care about the user selected target path I removed that dialog. Also I needed to take special care when uninstalling.
public override void OnAfterInstall(IDictionary savedState)
{
base.OnAfterInstall(savedState);
// Get original file folder
string originDir = Context.Parameters["targetdir"];
// Get new file folder based on the dir of sample.txt
string newDir = Path.GetDirectoryName(Context.Parameters["dirfile"]);
// Application executable file name
// (or loop for all files on the path instead)
string filename = "ApplicationName.exe";
// Move or copy the file
File.Move(Path.Combine(originDir, filename), Path.Combine(newDir, filename)));
}
I am new to the batch script programming.Getting error while executing batch file if I give the relative path.
I have following folder structure
Script folder - C:\batch\script\ServiceRegister.bat
Bin path - C:\batch\bin\ERecruitGenerateReportsWindowsService.exe
ServiceRegister.bat Batch file –
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0%~1\bin\ERecruitGenerateReportsWindowsService.exe
When I execute ServiceRegister.bat file I got the error:
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\batch\script\bin\ERecruitGenerateReportsWindowsService.exe' or one of its dependencies. The system cannot find the file specified.
I am using “%~dp0%~1” to go one level up in the directory still it gets its current path.
%~dp0%~1 - C:\batch\script\
I need the C:\batch\ path. How I can get this path?
It works fine If I give the absolute path -
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\batch\bin\ERecruitGenerateReportsWindowsService.exe
Your attempt to use %~1 to go up one level in the directory structure is inventive and totally invalid syntax. The proper syntax is just as simple - use ..\.
A leading \ is not required because %~dp0 ends with a \.
%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0..\bin\ERecruitGenerateReportsWindowsService.exe