How to transfer a folder with the files name and size to excel? - excel-2007

Is it possible to transfer to excel the exact name of the files and its size from a folder, without having coding knowledge?

With no coding, you could run dir /C *.xls > a.txt, then import a.txt into Excel.

Related

Permission denied on file deletion and previously copied in VBA

Facing one issue....
Basically, I have a bouton on Word to launch a macro treatment. This treatment saves the open file, copies the open file from C:/ to Z:/, writes an XML file in Z:/, launches another treatment that will read both files in Z:/ and then, clears the files in Z:/.
C:/ is my local computer, Z:/ is a shared drive...
I managed to copy the file from C:/ to Z:/ with :
fsoObject.CopyFile ActiveDocument.Path & "\" & ActiveDocument.name, "Z:\" & ActiveDocument.name, True
Treatment goes well, but I'm completely unable to delete the file in Z:\ with this :
fsoObject.DeleteFile "Z:\*", True
I always get "Permission Denied"... Cannot delete it manually as well, except if I close ENTIRELY Word (and not only the file that was copied)...
Is there a way to avoid the file locking by Word ?
Thx !
Use a vba command to close the file after you have performed your operations. Then apply the delete command.

Excel file name changed dynamically

I used an excel template. In my ssis package at first the template is copied in the working directory and package execute. In the next run the excel file which is already existed in the working directory it moved into BACKUP folder and again the template file copied. It works good.
But i want to do something when i move it i want to rename it like is the previous file name is Input_01 in the next move it will input_02. How can i do this?
i am using Execute process task toolbox in SSIS pacakge.
and a .bat file is called. in the .bat file i write
move "E:\InputFolder\Input.xls" "D:\Backup"
copy "E:\Template\Input.xls" "E:\InputFolder\Input.xls"
I want a ouput in the backup folder the excel files are like
Input_01,Input_02.... what will be my command?
Here's how to do it with a batch file:
#echo off
set cnt=1
for /f %%f in ('dir /b "D:\Backup\Input_*.xls"') do set /a cnt+=1
if %cnt% lss 10 (move "E:\InputFolder\Input.xls" "D:\Backup\Input_0%cnt%.xls") else (move "E:\InputFolder\Input.xls" "D:\Backup\Input_%cnt%.xls")
copy "E:\Template\Input.xls" "E:\InputFolder\Input.xls"
You can have more control over your files' naming convention (not to mention deletion of old files) if you use a Script Task, though.
can we use a 'File system task' instead. It helps us Renaming a file. You will have to use a 'For-Each loop Container' as well.

VBA script to create dir and file

I would like to create directory folders and files using excel VBA script. I have the following String
/path/project/command.exe
And I create folders and file under drive D:\ likes this D:\path\project\command.exe.My file may be vary .exe or .txt or .doc or etc.. I already used MkDir but I only create folder not create file. So help me to create directory folders and files using excel VBA script. If exe file or some file types that are not create from vba, I only need to create some temporary files for replacement of exe file.
If you want to create blank files you could use cmd's fsutil:
Sub createBlankFile()
Shell "fsutil file createnew ""D:\path\project\command.exe"" 0", vbNormalFocus
End Sub
The 0 refers to the size of the file.

VBA Dialogue prevent user from changing extension FileFilter option

Say I have a directory with multiple file types, and that I have already set the file filter to show only CSV files
paths = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv", _
MultiSelect:=True)
The above code does apply the filter correctly.
Now when I put an any filter text in the file name editbox and hit open/enter, the file extension filter no longer works/gets reset to the user's filter.
This means that if I have files called test.doc and test.csv in the same directory and type in test* in the open file dialog editbox, both the Word document and the CSV file will show as selectable.
Is this a bug and is there a way around this? That is, I want the user-defined filter to be an addition to the predefined filter.
I think I understand what you're asking. I knew I had this one laying around somewhere.
This is without muti select:
fileOpen = Application.GetOpenFilename("Text Files (*.csv),*.csv,Word Files (*.doc),*.doc")
This is with Muti select plus title:
fileOpen = Application.GetOpenFilename("Text Files (*.csv),*.csv,Word Files (*.doc),*.doc", 1, "Pick Your CSV File", , True)
Hope that helps!

BCP - Exported files (docx, xlsx & pptx) are corrupted

I am using the below bcp command to export the binary files from the filestream db and all other files are seems to be exported fine (i.e. txt, pdf, rtf, image files & etc) except docx, xlsx & pptx files. I am able to export these files (i.e. docx, xlsx & pptx) but I am getting a warning/error message when opening those files and then it opens the file properly.
BCP "SELECT content FROM [dbo].[Contents] WHERE ID=1" queryout "C:\Temp\" -T -S (local) -f C:\Temp\files.fmt
I am getting the below message when opening docx, xlsx & pptx files:
XLSX - Excel found unreadable content and Do you want to recover the contents of this document?
DOCX - The file test.docx cannot be opened bcos there are problems with the content and then Excel found unreadable content and Do you want to recover the contents of this document?
Also, I have this in my files.fmt file:
10.0
1
1 SQLBINARY 0 0 "\t" 1 content ""
Any help will be much appreciated.
I am not 100% sure if your problem was the same as what I have had but in my case, I found that the problem was actually in the writing part, not in the reading part. For example, my original writing code was like this:
Dim FILE_CONTENT(len) As Byte
File.InputStream.Read(FILE_CONTENT, 0, len)
SaveFileToDatabase(FILE_NAME, CONTENT_TYPE, FILE_CONTENT)
When I changed the first line as the following :
Dim FILE_CONTENT(0 To len - 1) As Byte
the reading error disappeared. I just forgot that VB actually allocates N+1 bytes (O to N) by default when you dimension it without specifying the lower bound. See similar situation described here: Uploaded Docx Files are getting corrupted . hope that helps.