Laravel rename a directory using Storage facade - laravel

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.

Related

Windows 10 create a softlink to a file

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

Windows 7 Folder broken creation glitch

I wrote a program in python that created folders. I'm having difficulty removing some of the folders due to this glitch.
I already figured out how to prevent it. But for the folders already created are irremovable. I get this error message when trying to delete them.
Could not find this item. This is no longer located at ... Verify the items location and try again [Try Again][Cancel]
I tried removing the folders by typing dir /x into a console
and then using the shorthand of the folder name with the del program. ex: del FOLDER~1
But that only works some of the time.
The only difference between the broken and non broken folders is the space at the end of the folder name when creating.
How to make a broken directory:
mkdir "broken folder /"
How to make a normal directory
mkdir "normal folder/"
Extra info:
The folders can still be used. The files inside can be deleted. Just not the folder itself or its parent folder.
When this glitch occurs in python using os.mkdir it also creates two directories with the exact same name. Only one can be deleted regularly.
I wrote a python script that fixes all the broken folders. So if anyone hits this issue. Hope this helps. Just drop into whatever folder is full of broken folders. Its kind of poorly made. But gives an idea about what you need to do.
from glob2 import glob
import os
import shutil
#find all folders
folders = glob("./**/")
# for each folder check if they exist and rename them to have an A at the end of their name.
for fold in folders:
if fold != ".\\":
if os.path.exists(fold):
name = fold.rsplit("\\", 2)[-2] + "A"
print(name)
print(fold)
os.rename(fold, name)

What does slash dot refer to in a file path?

I'm trying to install a grunt template on my computer but I'm having issues. I realized that perhaps something different is happening because of the path given by the Grunt docs, which is
%USERPROFILE%\.grunt-init\
What does that . mean before grunt-init?
I've tried to do the whole import manually but it also isn't working
git clone https://github.com/gruntjs/grunt-init-gruntfile.git "C:\Users\Imray\AppData\Roaming\npm\gru
nt-init\"
I get a message:
fatal: could not create work tree dir 'C:\Users\Imray\AppData\Roaming\npm\.grunt-init"'.: Invalid argument
Does it have to do with this /.? What does it mean?
The \ (that's a backslash, not a slash) is a directory delimiter. The . is simply part of the directory name.
.grunt-init and grunt-init are two distinct names, both perfectly valid.
On Unix-like systems, file and directory names starting with . are hidden by default, which is why you'll often see such names for things like configuration files.
The . is part of a directory name. Filenames can contain . . The \ is a separator between directory names.
Typically, files or directories starting with . are considered "hidden" and/or used for storing metadata. In particular, shell wildcard expansion skips over files that start with ..
For example if you wrote ls -d * then it would not show any files or directories beginning with . (including . and .., the current and parent directories).
Linux hides files and directories whose names begin with dot, unless you use the a (for "all") option when listing directory contents. If this convention is not followed on Windows, your example is probably just a carryover.
It may well be something behind the scenes (later) expects that name to match exactly. While I like things, installers, for example, to just do what I said, I realize that keeping default value is the most tested path.
Directories starting with a dot are invisible by default on xNIX systems. Typically used for configurations files and similar in a users home directory.
\ before " has a special meaning on windows, the error is because windows won't let you create a file containing " as part of its name.

What is common practice for the location of temporary files after Windows XP [duplicate]

Currently I am using following function to get the temporary folder path for current user:
string tempPath = System.IO.Path.GetTempPath();
On some machines it gives me temp folder path of current user like:
C:\Documents and Settings\administrator\Local Settings\Temp\
On some machines it gives me system temp folder path like:
C:\Windows\TEMP
MSDN Documentation also says that above API returns current system's temporary folder.
Is there any other API available which gives me current user's temporary folder path like this:
C:\Documents and Settings\administrator\Local Settings\Temp\
System.IO.Path.GetTempPath() is just a wrapper for a native call to GetTempPath(..) in Kernel32.
Have a look at http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
It's not entirely clear to me whether "The Windows directory" means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they're not set and it's taking a fallback to the windows temp path.
DO NOT use this:
System.Environment.GetEnvironmentVariable("TEMP")
Environment variables can be overridden, so the TEMP variable is not necessarily the directory.
The correct way is to use System.IO.Path.GetTempPath() as in the accepted answer.
I have this same requirement - we want to put logs in a specific root directory that should exist within the environment.
public static readonly string DefaultLogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
If I want to combine this with a sub-directory, I should be able to use Path.Combine( ... ).
The GetFolderPath method has an overload for special folder options which allows you to control whether the specified path be created or simply verified.

Where should my windows app store cache and tempfiles? [duplicate]

Currently I am using following function to get the temporary folder path for current user:
string tempPath = System.IO.Path.GetTempPath();
On some machines it gives me temp folder path of current user like:
C:\Documents and Settings\administrator\Local Settings\Temp\
On some machines it gives me system temp folder path like:
C:\Windows\TEMP
MSDN Documentation also says that above API returns current system's temporary folder.
Is there any other API available which gives me current user's temporary folder path like this:
C:\Documents and Settings\administrator\Local Settings\Temp\
System.IO.Path.GetTempPath() is just a wrapper for a native call to GetTempPath(..) in Kernel32.
Have a look at http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
It's not entirely clear to me whether "The Windows directory" means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they're not set and it's taking a fallback to the windows temp path.
DO NOT use this:
System.Environment.GetEnvironmentVariable("TEMP")
Environment variables can be overridden, so the TEMP variable is not necessarily the directory.
The correct way is to use System.IO.Path.GetTempPath() as in the accepted answer.
I have this same requirement - we want to put logs in a specific root directory that should exist within the environment.
public static readonly string DefaultLogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
If I want to combine this with a sub-directory, I should be able to use Path.Combine( ... ).
The GetFolderPath method has an overload for special folder options which allows you to control whether the specified path be created or simply verified.

Resources