Create new file in EnvDTE.SolutionFolder without specifying full path - visual-studio

The EnvDTE80.SolutionFolder interface (https://learn.microsoft.com/en-us/dotnet/api/envdte80.solutionfolder) has an AddFromFile() method, but requires the absolute full path of an existing file. Unfortunately the solution folder object itself doesn't contain a property with the path of the folder on disk.
Is there an easy way to create a new (text) file in a SolutionFolder without needing to know it's full absolute path? We just want a new file which is a direct child of the folder.
Something like this:
EnvDTE80.SolutionFolder folder;
var file = folder.CreateFile("myFile.txt");
But not:
EnvDTE80.SolutionFolder folder;
var file = folder.AddFromFile("c:\path_to_folder\myFile.txt");

Unfortunately the solution folder object itself doesn't contain a property with the path of the folder on disk.
Exactly. It's because the solution folders are virtual, they are not related to any physical folders in the file system. You can have "MyFolder" solution folder in your solution and no "MyFolder" in you file system.
You CAN have also the physical folder just for the convenience:
C:\Solution
MyFolder
myFile.txt
But even then, this physical folder is absolutely unrelated to the solution folder. The solution folder may contain files from anywhere, even from outside the solution root physical folder. That's why you must supply the full path if you want to add a file to a solution folder.
If you know that you have the structure of solution folders mirrored also in physical folder structure, you can construct the full path manually. Get the directory name of the solution with EnvDTE80.Solution.FullName, combine it with the EnvDTE80.SolutionFolder.Parent.Name and then with the file name.

Related

I'm looking to have a Folder recognise new files being saved into it and then copy new files into a collated folder

In MacOS i want a folder action to trigger when i place a new file into a subfolder. The action should grab a newly added file to the folder and copy it to another folder where all the latest files are collated and can be viewed together. I also want the script to delete any old version of the same file it copies across to the collated folder. The trouble is the file names are slightly dfferent as they have a version number in them. The version number is defined as "v01a" to start with but can change to "v01b" or "v01e" or "v02a" or "v03c".
So if a file called "1234_ProjectName_Image01_COMP_v01a.jpg" already exists and a new file called "1234_ProjectName_Image01_COMP_v01b.jpg" is added the the file called "1234_ProjectName_Image01_COMP_v01a.jpg" needs to be deleted from the destination folder.
I've tried a few times to get started in automator but never really get the pieces in place for it to be useful.
(SOURCE)
Dailies/_Internal
Dailies/_Internal/Image01/1234_ProjectName_Image01_COMP_v01a.jpg
Dailies/_Internal/Image02/1234_ProjectName_Image02_COMP_v01a.jpg
Dailies/_Internal/Image03/1234_ProjectName_Image03_COMP_v01a.jpg
(DESTINATION)
Dailies/_Latest
Dailies/_Latest/1234_ProjectName_Image01_COMP_v01a.jpg
Dailies/_Latest/1234_ProjectName_Image02_COMP_v01a.jpg
Dailies/_Latest/1234_ProjectName_Image03_COMP_v01a.jpg
If a new file is added called
Dailies/_Internal/Image01/1234_ProjectName_Image01_COMP_v02a.jpg
then this file is copied from its source folder and put into the Destination folder.
(DESTINATION)
Dailies/_Latest
Dailies/_Latest/1234_ProjectName_Image01_COMP_v01a.jpg
Dailies/_Latest/1234_ProjectName_Image01_COMP_v02a.jpg
Dailies/_Latest/1234_ProjectName_Image02_COMP_v01a.jpg
Dailies/_Latest/1234_ProjectName_Image03_COMP_v01a.jpg
Here there is already an image with the same name except the version number so the script should also delete the old file leaving me with.
(DESTINATION)
Dailies/_Latest
Dailies/_Latest/1234_ProjectName_Image01_COMP_v02a.jpg
Dailies/_Latest/1234_ProjectName_Image02_COMP_v01a.jpg
Dailies/_Latest/1234_ProjectName_Image03_COMP_v01a.jpg
I can't for the life of me figure out how to do this, any ideas would be greatly appreciated.
Screengrab of my very basic automator here

Automatically checking the existence of folders in a path

I have a lot of folders, each folder has someone's surname as the name. I want to move all these surname folders into a different path, how would I automatically check the path I want to move them to, for the same name.
For example. Let's say in C:/Downloads I have a folder called Nunes. How would I make it so when I upload another folder called nunes, it alerts me that that folder already exists?

Replacing a files into multiple folders/subdirectories

Is there a way in command prompt to take files and replace it into another folder and it's sub directories based on it's name?
I have an images in my folder and i have folder have sub directories that have the same name of images, what i want to do i need to replace the image in the sub directories base on the image in my main folder.
I searched for other similar questions and I found a few topics that might interest you.
Batch file to move files based on name w/o creating new folders
Batch Create a Folder Based on Filename, and Move Multiple Related
Files to The Created Folder
If you post the code you have already tried, it may be possible to fix any issues you are having.

How can I determine which folder the user was browsing when my program was invoked from the "sent to" menu?

I put a shortcut to my application in SendTo. Now I can select some files in Explorer and send them to my application. But how can I get the path where the files are? My program is supposed to create a new file in the parent directory that's common to all the received file names.
For example, if I have these files:
C:\one.txt
C:\1\
I select the file one.txt and the directory 1 in Explorer. How can I find out that the starting directory for these files is C:\?
I know I can use ParamStr() to get files' paths, but what then?
I could try to get common directory for all the files passed to my application, but if I select in C:\ directories 1 and 2 and these directories look like this:
C:\1\4\5\one.txt
C:\1\4\two.txt
Then the starting directory is C:\1\4.
Prior to Windows 7, all files selected in Explorer always reside in the same directory, so it's easy to know which directory the user was browsing. It's the same as the directory of any one file. Use ExtractFilePath for that.
As of Windows 7, though, Explorer lets you put directories into groups called libraries. All the files from all the folders are displayed together in a single view. Users can select files from multiple directories and send them all to your program at once. The view doesn't represent any real directory on the disk, so the question asked here is meaningless.
As an alternative, you could decide use the ancestor directory common to all the files sent to your program, but that won't tell you much. For one thing, if the files reside on multiple drives, the common directory will be the empty string. The directory you calculate also might not be writable by the current account, even if the directories of one or more of the selected files are.
It will probably be easier to just use the directory of the first file you receive, or even to display a UI that asks the user what directory to use in the cases you can't determine it automatically. (Maybe you could pre-populate the result with the first directory, so the user doesn't have to do anything but approve your suggestion in the common case.)
I think I will just take all the filenames passed to my program via ParamStr and use this function:
http://delphi.about.com/od/delphichallengesexercises/qt/delphi-extract-base-path-challenge.htm
to find common base path which should be the path where the SendTo was invoked.

Mac OS X File / Folder Management: When to Copy instead of Move

The Finder uses some kind of rules to determine if an Item can be moved or will be copied. After dragging an Item, in certain cases Finder shows a drag-copy-cursor. Are these rules in an API available? Checked with Spotlight-Metadata, NSURL and NSFileManager: no result.
Here's what i came up with:
if a Folder contains a ".localized" File: the folder is copied
if a Folder is listed anywhere in a NSSearchPathDirectory
Is my assumption right? or has it to do with NSURLIsSystemImmutableKey or NSURLIsUserImmutableKey which i thought is the "Locked" flag?
Furthermore depending on various other Metadata like write-permissions and locked-flag:
ON SOURCE:
moving a readonly file: move is possible
moving a readonly folder needs login from an admin
moving a locked file creates a copy
moving a locked folder creates a copy
moving a folder with a locked file inside: move is possible
moving a selection with both locked and unlocked items creates a copy
moving a dropbox writeonly folder: move is possible
writeonly files do not exist in Finder
moving a file without any permissions: move is possible (as the move rights depend on the enclosing folder)
moving a folder with a file without any permission: move is possible (as long its a move, for copy it asks for login)
if a Folder contains a ".localized" File: the folder is copied
if a Folder is listed anywhere in a NSSearchPathDirectory (home directory, ...) it is copied
if a folder contains another book: move is possible
ON TARGET:
moving an item into a dropbox creates a copy
moving an item into a locked folder: not possible
moving an item into a read-only folder: asks for login
*) Regarding the Finder: if a file or directory is being dragged from one volume to another, it will (by default) be copied. If the action is being performed on the same volume the file or folder will (by default) be moved. As a side note to file operations on volumes: 'moving' things across different filesystemes behaves differently, again. Normally, moving a file or directory doesn't mean 'copying' and 'deleting' the original afterwards - only their links within the filesystem usually become modified but here and then, it actually behaves exactly like that.
*) Furthermore, take care of the objects permissions: if filesystem permissions to that source file or a directory (and it's content within) doesn't allow write operations to it, it will be copied again.

Resources