How to check if a specific file exists in a shared folder using Powershell? - powershell

I want to check the existence of file which is present on shared location using powershell command.
I am using below query,which is giving wrong result for shared folder.
Test-Path " \computer\Software\aaa.txt"
Please help me to sort out the issue..

Related

Copy-PnPFile returns 401

I am traying to copy files betwen SP Document Librarys, with PnP PowerShell command "Copy-PnPFile",
but I get "Copy-PnPFile : The remote server returned an error: (401) Unauthorized"
In the script before this comand I am reading, items, creating folder and it works, only Copy-PnPFile dont work.
Copy-PnPFile -SourceUrl $Item["FileRef"] -TargetUrl $TargetFileUrl
Make sure $Item["FileRef"] is a relative path. Of course $TargetFileUrl should also be a relative path.
Microsoft Official:
Copy-PnPFile:Copies a file or folder to a different location. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Currently there is a 200MB file size limit for the file or folder to be copied. Notice that if copying between sites or to a subsite you cannot specify a target filename, only a folder name.
Here is a nice article for your referenceļ¼š
SharePoint Online: Copy File Between Document Libraries using
PowerShell
My mistake.
In source and target relative path forgot to include "SiteCollectionURL".

Matlab, dos() command : files remain "in use"

After executing some simple commands like
dos('copy *.txt new.txt', '-echo')
dos('echo. 2 > EmptyFile.txt', '-echo')
I tried to delete the folder in which these files were created. However, Windows gives me the message
"cannot delete "FolderName": the folder is being used by another person/program".
I have to close Matlab to make it work.
How do I solve this? I guess it's something like closing the "session" of cmd commands...
What you're not showing is the change of working directory to your folder. Windows won't let you delete a folder that a process has as a current working directory.
The solution is simple: change the working directory out of that folder. Say:
cd('..')

Find folder name from a specific location

How can I find a folder from a specific location using command prompt.
eg:- I want to search files from desktop and there are around 10 files that contains the name starting from A and i want locations of all such file with file name.
I know it can be done using find commnad but I am unable to write the correct code for it.
Thanks for the help
you can find all files from a directory and sub directories that start with 'a' using this:
dir /b /s a*.*

Copy file from server share to local folder with Applescript

I have a folder on a server which is shared with guest access enabled. I want to be able to copy a file from that folder to a local machine with Applescript. So far I have:
property source : "server:sharedfolder:file.ext"
property destination : "Macintosh HD:Users:User:Documents:Folder"
tell application "Finder"
copy file "source" to folder "destination"
end tell
Which I think should work. But I get the error: Can't set folder source to destination number 10006. Any ideas?
Thanks.
you need to remove the quotes around your declared properties:
property source : "server:sharedfolder:file.ext"
property destination : "Macintosh HD:Users:User:Documents:Folder:"
tell application "Finder"
copy file source to folder destination
end tell
It is also good practice to terminate your folder paths with a ":".
HTH
Your current script reads: "Copy the variable source to the variable destination." I'm assuming you don't want to just change the variables around; you're using the wrong command. See my answer to this question to learn more.

Where does CGI.pm normally create temporary files?

On all my Windows servers, except for one machine, when I execute the following code to allocate a temporary files folder:
use CGI;
my $tmpfile = new CGITempFile(1);
print "tmpfile='", $tmpfile->as_string(), "'\n";
The variable $tmpfile is assigned the value '.\CGItemp1' and this is what I want. But on one of my servers it's incorrectly set to C:\temp\CGItemp1.
All the servers are running Windows 2003 Standard Edition, IIS6 and ActivePerl 5.8.8.822 (upgrading to later version of Perl not an option). The result is always the same when running a script from the command line or in IIS as a CGI script (where scriptmap .pl = c:\perl\bin\perl.exe "%s" %s).
How I can fix this Perl installation and force it to return '.\CGItemp1' by default?
I've even copied the whole Perl folder from one of the working servers to this machine but no joy.
#Hometoast:
I checked the 'TMP' and 'TEMP' environment variables and also $ENV{TMP} and $ENV{TEMP} and they're identical.
From command line they point to the user profile directory, for example:
C:\DOCUME~1\[USERNAME]\LOCALS~1\Temp\1
When run under IIS as a CGI script they both point to:
c:\windows\temp
In registry key HKEY_USERS/.DEFAULT/Environment, both servers have:
%USERPROFILE%\Local Settings\Temp
The ActiveState implementation of CGITempFile() is clearly using an alternative mechanism to determine how it should generate the temporary folder.
#Ranguard:
The real problem is with the CGI.pm module and attachment handling. Whenever a file is uploaded to the site CGI.pm needs to store it somewhere temporary. To do this CGITempFile() is called within CGI.pm to allocate a temporary folder. So unfortunately I can't use File::Temp. Thanks anyway.
#Chris:
That helped a bunch. I did have a quick scan through the CGI.pm source earlier but your suggestion made me go back and look at it more studiously to understand the underlying algorithm. I got things working, but the oddest thing is that there was originally no c:\temp folder on the server.
To obtain a temporary fix I created a c:\temp folder and set the relevant permissions for the website's anonymous user account. But because this is a shared box I couldn't leave things that way, even though the temp files were being deleted. To cut a long story short, I renamed the c:\temp folder to something different and magically the correct '.\' folder path was being returned. I also noticed that the customer had enabled FrontPage extensions on the site, which removes write access for the anonymous user account on the website folders, so this permission needed re-applying. I'm still at a loss as to why at the start of this issue CGITempFile() was returning c:\temp, even though that folder didn't exist, and why it magically started working again.
The name of the temporary directory is held in $CGITempFile::TMPDIRECTORY and initialised in the find_tempdir function in CGI.pm.
The algorithm for choosing the temporary directory is described in the CGI.pm documentation (search for -private_tempfiles).
IIUC, if a C:\Temp folder exists on the server, CGI.pm will use it. If none of the directories checked in find_tempdir exist, then the current directory "." is used.
I hope this helps.
Not the direct answer to your question, but have you tried using File::Temp?
It is specifically designed to work on any OS.
If you're running this script as you, check the %TEMP% environment variable to see if if it differs.
If IIS is executing, check the values in registry for TMP and TEMP under
HKEY_USERS/.DEFAULT/Environment