When I download a file that contains "." in its name my code throws an exception:
No route matches "/test/download/File%201.0%20BETA.docx"
The file name is: "File 1.0 BETA.docx"
Here is my code for downloading file in my controller file:
def download
path = params[:path]
path = "#{Rails.root}/public/data/" + path
send_file(path+"."+params[:format])
end
How can I solve it?
This is most likely caused by your routes not supporting multiple "." in the path. For example, if your routes look like this:
'/test/download/:path.:extension'
Then that will break if the filename contains more then one "."
Instead you could do a routing like this:
'/test/download/*path.:extension'
That will make sure that multiple "." is functioning
Related
I'm trying to create a python program that allows you to dynamically choose the folder to save the download.
'outtmpl' lets you choose an output as a simple path such that
'e:/python/downloadedsongs/%(title)s.%(ext)s'
is a valid path and will let you save to the downloadedsongs folder
But With the function that defines the choose folder button
def openLocation():
global Folder_Name
Folder_Name = filedialog.askdirectory()
print(Folder_Name)
why does
f'{Folder_name}/%(title)s.%(ext)s'
not return a valid path, the program outright ignores the variable. I thought at first i was having a fstring issue because %s was pythons old format for f'strings but I have also tried these variances with no success
'outtmpl': Folder_Name + '/' + '%(title)s.%(ext)s', (no errors but cannot find output)
'outtmpl': '%(Folder_Name)s%(title)s.%(ext)s',
%()s is the old version of fstrings I was conflating the two.
answer ended up looking like 'outtmpl': Folder + '/%(title)s.%(ext)s'
I try to list specific file name from directory. but I got error code 53 with Getattr function.
In my case,
error occurred when file path & file name length is greater than 259 in same directory.
Question is
how much length does Getattr function support?
how can i solve this error?
I have not found this on official website. But i have tested it and it is working fine till length is 260.
You can use relative path of directory.
Or
You can Prefix a path with \\?\, like \\?\C:\TEST\test.txt. This will convert DOS path names to native OS path names. Refer this.
Dim file_path = "\\?\C:\TEST\test.txt"
Id like to rename all my files in one specific directory. They shall all get the identical extension. I tried using a for loop:
For Each s As String In IO.Directory.GetFiles(Environ("PROGRAMFILES(x86)"), "*", IO.SearchOption.AllDirectories)
Try
My.Computer.FileSystem.RenameFile(s, s & ".new")
Catch ex As Exception
End Try
So that the name s (as string) becomes s & extension ".new"
However, that didnt work.
If you had read the documentation for the RenameFile method you are calling, as you should have to begin with but especially when it didn't work, then you would know that the first argument requires the full path of the file while the second argument requires just the new name of the file. That means that you need this:
My.Computer.FileSystem.RenameFile(s, My.Computer.FileSystem.GetName(s) & ".new")
The File.Move method requires full paths in both cases because it supports renaming within the same folder and moving to a different folder. You say that you want to use RenameFile but didn't bother to note how it is different, i.e. it only supports renaming within the same folder so specifying that path twice is pointless and allowing different paths to be specified would cause problems.
I am using Anypoint Studio 7 and Mule 4.1.
A product file in csv format with a filename that will include the current timestamp will be added to a directory on a daily basis and needs to be processed. To do this we are creating a mule workflow using the file connector and want to configure the file path field to only read csv file formats regardless of name.
At the moment, the only way I can get it to work is by specifying the filename in the file path field which looks like this:
C:/Workspace/product-files-v1/src/main/resources/input/products-2018112011001111.csv
when I would like to specify some kind of wildcard in the file path similar to this:
C:/Workspace/product-files-v1/src/main/resources/input/products-*.csv
but the above does not work.
What is the correct wildcard syntax and also is there a way to specify the relative file path instead of the absolute one as when I try to specify a relative file path I get an error too?
Error message in logs:
********************************************************************************
Message : Illegal char <*> at index 108: C:/Workspace/product-files-v1/src/main/resources/input/products-*.csv.
Element : product-files-v1/processors/1 # product-files-v1:product-files-v1.xml:16 (Read File)
Element XML : <file:read doc:name="Read File" doc:id="fdbbf477-e831-4e7c-827c-71efd1d2e538" config-ref="File_Config" path="C:/Workspace/product-files-v1/src/main/resources/input/products-*.csv" outputMimeType="application/csv" outputEncoding="UTF-8"></file:read>
Error type : MULE:UNKNOWN
--------------------------------------------------------------------------------
Root Exception stack trace:
java.nio.file.InvalidPathException: Illegal char <*> at index 108: C:/Workspace/product-files-v1/src/main/resources/input/products-*.csv
Thanks for any help
i am assuming you need to user a <file:matcher> when you want to filter or read certain type of files from a directory.
an example would be
<file:matcher
filename-pattern="a?*.{htm,html,pdf}"
path-pattern="a?*.{htm,html,pdf}"
/>
I have a path (as a string) to a directory. In that directory, are a bunch of text files. I want to go to that directory open it, and go to each text file and read the data.
I've tried
f = io.open(path)
f:read("*a")
I get the error "nil Is a directory"
I've tried:
f = io.popen(path)
I get the error: "Permission denied"
Is it just me, but it seems to be a lot harder than it should be to do basic file io in lua?
A directory isn't a file. You can't just open it.
And yes, lua itself has (intentionally) limited functionality.
You can use luafilesystem or luaposix and similar modules to get more features in this area.
You can also use the following script to list the names of the files in a given directory (assuming Unix/Posix):
dirname = '.'
f = io.popen('ls ' .. dirname)
for name in f:lines() do print(name) end