-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify filename (not just directory) when downloading GDrive file #188
Comments
The invalid filename part of this issue could be addresses as you did in #169. While I could also find specifying a desired filename would be beneficial, I don't know how to suggest to reconcile this filename option with the ability to send an array of File IDs to download. |
#169 sounds like it will change the target filename to be safe, but will not tell me what that target filename is. So I have to do some manual string manipulation and hope it matches the behavior of PSGSuite. I'm writing an automated backup and restore script, so immediately after downloading a file, I need to pass it to For sending an array of FileIDs, can I simply specify an array of local filenames to match, with a one-to-one relationship? Or simply disallow multiple FileIDs when I supply a target filename? So if I want to download multiple FileIDs to specific local filenames, I'll need to do it in a |
@cspotcode, I see the issue you would have with not knowing the output filename. I would as well in my intended process. How about a property added to the output object to provide the actual file name used to output the file? In this case the output object would have a @scrthq I hope this discussion helps. I'm not trying to dictate any design ideas, but rather come up with a potential solution that made fit more needs. Your choice! |
That would work for me. Today I generate a temp filename using OS APIs, download to that filename, then delete the temp file when I'm done. (I've patched my local copy of PSGSuite) With your proposed solution, I would instead generate a new temp directory name, create the new empty directory, and download the file into that new directory. Then I would delete my temp directory. This would be necessary to avoid any possible name conflicts with other files in the OS's temp directory. On Linux, |
@cspotcode - I appreciate the feedback! How does expanding the To satisfy the resulting FileName piece, I can also add in the final Sample code to test the special-character-replacement against a string of your own (feedback appreciated in case there are characters missed!): $Name = 'backup__2019-05-19T04:24:43Z__Personal-dev/@creationix/nvm.zip'
$Name -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" Resulting output on Windows 10: Sample returned object when downloading something to a specified path: @WJurecki - Thanks for jumping in here!! |
@cspotcode - With the above adjustment, existing usage could continue to function as is and you also have the option of piping in filenames and capturing the |
…, #197 (#198) ## 2.28.0 * [Issue #188](#188) * Added: `Get-GSDriveFile` now supports specifying a full file path. * Fixed: `Get-GSDriveFile` will now replace any special path characters in the filename with underscores * Added: The File object returned by `Get-GSDriveFile` will now include an additional `OutFilePath` property if the file is downloaded. This property will contain the full path to the downloaded file. * [Issue #190](#190) * Fixed: `Fields` parameter on `Get-GSDriveFile` and `Update-GSDriveFile` were not being honored. * [Issue #192](#192) * Added: Parameters to `Update-GSDriveFile`: * `CopyRequiresWriterPermission [switch]` * `Starred [switch]` * `Trashed [switch]` * `WritersCanShare [switch]` * [Issue #194](#194) * Added: Parameters to `Update-GSChromeOSDevice`: * `AnnotatedAssetId [string]` * `AnnotatedLocation [string]` * `AnnotatedUser [string]` * `Notes [string]` * [Issue #195](#195) * Added: `Limit` parameter with `First` alias to the following `List` functions: * `Get-GSActivityReport` * `Get-GSAdminRole` * `Get-GSAdminRoleAssignment` * `Get-GSCalendar` * `Get-GSCalendarAcl` * `Get-GSCalendarEvent` * `Get-GSChromeOSDevice` * `Get-GSDataTransferApplication` * `Get-GSDrive` * `Get-GSDriveFileList` * `Get-GSDrivePermission` * `Get-GSGmailMessageList` * `Get-GSGroup` * `Get-GSGroupMember` * `Get-GSMobileDevice` * `Get-GSResource` * `Get-GSTask` * `Get-GSTaskList` * `Get-GSUsageReport` * `Get-GSUser` * `Get-GSUserLicense` * [Issue #196](#196) * Fixed: `Get-GSTeamDrive` was not paginating through the results. * [Issue #197](#197) * Renamed: `Get-GSTeamDrive` has been changed to `Get-GSDrive`. `Get-GSTeamDrive` has been turned into an alias for `Get-GSDrive` to maintain backwards compatibility. * Replaced: `SupportsTeamDrives = $true` with `SupportsAllDrives = $true` on all functions that have it. * Miscellaneous * Fixed: `Export-PSGSuiteConfig` is faster due to safely assuming that the P12Key and/or ClientSecrets values have already been pulled from the corresponding keys. * Fixed: Incomplete documentation for `Test-GSGroupMembership`. * Added: `UseDomainAdminAccess` switch parameter to `Get-GSTeamDrive` * Removed: `Get-GSUserLicenseListPrivate` by rolling the `List` code into `Get-GSUserLicense` * Removed: `Get-GSResourceListPrivate` by rolling the `List` code into `Get-GSResource`
…, #197 ## 2.28.0 * [Issue #188](#188) * Added: Get-GSDriveFile now supports specifying a full file path. * Fixed: Get-GSDriveFile will now replace any special path characters in the filename with underscores * Added: The File object returned by Get-GSDriveFile will now include an additional OutFilePath property if the file is downloaded. This property will contain the full path to the downloaded file. * [Issue #190](#190) * Fixed: Fields parameter on Get-GSDriveFile and Update-GSDriveFile were not being honored. * [Issue #192](#192) * Added: Parameters to Update-GSDriveFile: * CopyRequiresWriterPermission [switch] * Starred [switch] * Trashed [switch] * WritersCanShare [switch] * [Issue #194](#194) * Added: Parameters to Update-GSChromeOSDevice: * AnnotatedAssetId [string] * AnnotatedLocation [string] * AnnotatedUser [string] * Notes [string] * [Issue #195](#195) * Added: Limit parameter with First alias to the following List functions: * Get-GSActivityReport * Get-GSAdminRole * Get-GSAdminRoleAssignment * Get-GSCalendar * Get-GSCalendarAcl * Get-GSCalendarEvent * Get-GSChromeOSDevice * Get-GSDataTransferApplication * Get-GSDrive * Get-GSDriveFileList * Get-GSDrivePermission * Get-GSGmailMessageList * Get-GSGroup * Get-GSGroupMember * Get-GSMobileDevice * Get-GSResource * Get-GSTask * Get-GSTaskList * Get-GSUsageReport * Get-GSUser * Get-GSUserLicense * [Issue #196](#196) * Fixed: Get-GSTeamDrive was not paginating through the results. * [Issue #197](#197) * Renamed: Get-GSTeamDrive has been changed to Get-GSDrive. Get-GSTeamDrive has been turned into an alias for Get-GSDrive to maintain backwards compatibility. * Replaced: SupportsTeamDrives = True with SupportsAllDrives = True on all functions that have it. * Miscellaneous * Fixed: Export-PSGSuiteConfig is faster due to safely assuming that the P12Key and/or ClientSecrets values have already been pulled from the corresponding keys. * Fixed: Incomplete documentation for Test-GSGroupMembership. * Added: UseDomainAdminAccess switch parameter to Get-GSTeamDrive * Removed: Get-GSUserLicenseListPrivate by rolling the List code into Get-GSUserLicense * Removed: Get-GSResourceListPrivate by rolling the List code into Get-GSResource
Hey @cspotcode - This has been deployed in v2.28.0! Let me know if all is well or if you are seeing any issues! |
@scrthq - This appears to mostly work. There is a problem in your private Consider this: the \ still made it into the 'clean name' because the \ in the replace command needs to be escaped and actually \\ to work properly. Also, you should probably consider not only the name needs to be cleaned, but also the extension. consider these perfectly valid Drive filenames Sorry for the bad news. :-( |
Hey @WJurecki - Fair! The escaping is done against the current OS's invalid file and path characters, leaving anything alphanumeric or I definitely see your point though in that the files in Drive are just that, files, so it would make sense to also replace any valid path separators so the resulting file actually is a file and not something that got buried in an unexpected naming path. Testing it out actually returns an error since it's trying to access a path that doesn't exist due to the DirectorySeparatorChar being in the FileName: |
but I really appears that, at least on Windows, in the code |
Aha! This should do the trick instead, just wrapped the resulting character string in Test block: [PS 6.2.0]> 'Test\File/|Name' -replace "[$([RegEx]::Escape("$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')"))]","_"
Test_File__Name Thoughts @WJurecki ? |
@scrthq, that looks great! |
@WJurecki fixed rolled out in 2.28.1! |
Is your feature request related to a problem? Please describe.
I have Google Drive files that contain forward slashes in their filename (not their path, actually in the filename itself) I want to download the contents of such a file, but PSGSuite is trying to create a local file with slashes in the filename. This fails because it expects to traverse into a subdirectory that does not exist.
Describe the solution you'd like
I want to be able to specify the full, local filename to download to. This allows me to bypass any issues with the GDrive filename. For example:
It will download the contents of the remote file and save it as
baz.zip
, regardless of the filename on GDrive.Describe alternatives you've considered
Additional context
Here's the error I get. The filename (name, not path) on Google Drive is
backup__2019-05-19T04:24:43Z__Personal-dev/@creationix/nvm.zip
The name containers forward slash characters, which GDrive allows.The text was updated successfully, but these errors were encountered: