Windows get short path to a file before creating it - powershell

I'm trying to get a short path of a file before the file is created. I found an example which can convert a path to a shortPath if the folder or file existed. However, is there a way to get short path before the file even exist?

Thanks for all the comments. I think the easiest way to solve this problem is:
if file DOES NOT existed:
generate shortPath
return shortPath
else:
touch a new file with exact name expected.
generate shortPath
remove temp file
return shortPath

Related

Powershell Only:File name change according to mapping file and then copy to another directory

I have a mapping file in import.CSV as following:
Name|Business
Jack|Carpenter
Rose|Secretary
William|Clerk
Now, I have a directory which contains files like
90986883#Jack#Sal#1000.dat
76889992#Rose#Sal#2900.dat
67899279#William#Sal#1900.dat
12793298#Harry#Sal#2500.dat
Please note #Sal will always be there after Name. I need to pick these files and put into another directory and end result in second directory should look like.
90986883#Carpenter#Sal#1000.dat
76889992#Secretary#Sal#2900.dat
67899279#Clerk#Sal#1900.dat
Basically Files need to be renamed based upon CSV file and if Name is not there in file name , then there is no action required. Please note that source file should not be changed.
I will appreciate all kind of help.

django request absolute file path

using django requests, I am trying to get the absolute file path of original, uploaded file. The reason is I want to modify the original file so just the filename or some "media root" location just isn't enough.
I tried doing something like
request.FILES['file'].name
but that just gives me the name, not a path (neither absolute nor relative). google didn't really help, filenames are common, but path seems to be a special case. I hope it's even possible XP.
Thx in advance!
Try this.
myfile = request.FILES['filename']
fs = FileSystemStorage()
filename = fs.save(myfile.name, myfile)
uploaded_file_url = fs.url(filename)
print(uploaded_file_url)
Also make sure you add the 'django.core.files.storage.FileSystemStorage' under Middleware_classes in settings.py file

excel write to the same folder as m file

I have an m file which creates an excel file using xlswrite. If I do not specify the the folder for the xls to be output to, the default is the users folder. I would prefer that it goes to the same folder as the m file. Is there a way to generalize this without explicitly entering the m file location? I plan on distributing this m file and not everyone will keep their m files in the same folder.
To get the path where running m-file is stored, check out:
help mfilename
help fileparts
You could simply use the current working folder as the save location. This is whatever the "current directory" is in the matlab window.
You can access it using the command pwd. This returns a string that is the path to the directory.
Then append \filename.ext to it and you'll be good to go!

access folders and get files

I start with Matlab and would like to know how could I access to a folder and get contents to access files and read them.
I have a variable in workspace tmpfolder that is equal to 'path to folder' but I don't find how could I make dir(tmpfolder) and get files, browse any file content to get a string value...
I would start with dir() and fopen().
More generally, try starting at the beginning: Working with Files and Folders.
If you have an image file in jpeg format in another folder named myimage and a text file called mytext, use:
prefix_image='myimage';
prefix_data='mytext';
fileformat='.jpg';
dataformat='.txt';
folder='C:\Users\khaled\Documents\MATLAB\';
image = imread(strcat(folder,prefix_image,fileformat));
data=textread(strcat(folder,prefix_data,fileformat),'%f');

filemaker :: script doesn't find absolute pathed file

I try to import data from files inside a folder. herefor I mad ea script thats first imports all files from the folder and reads their paths. then I try to import these files and its data one after another.
my problem now is that FM tells me that it could not find the specified file at the place the path is leading to, but the file is there and the path is correct!
found out that you need to write "filemac:/" instead "file://"...