'Start Button' does the following:
Check the given folder path for .blf files
Copy all the existing .blf files to the destination folder
Show the directory of the folder in text file i,e. where the files are being created
Show the directory where the existing files are being copied i,e. Onto the server
Delete the file from parent folder after copying
How can i do the Point 5..where am i at fault?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Const DestinationDirectory As String = "C:\Users\nha4abt\Desktop\Move_Here"
'Show the parent folder path
TextBox1.Text = "C:\Users\nha4abt\Desktop\Ahmad_examaning_folder"
' Show the destination folder path
TextBox2.Text = DestinationDirectory
For Each FileName As String In directory.GetFiles("C:\Users\nha4abt\Desktop\Ahmad_examaning_folder", "*.blf")
File.Copy(FileName, Path.Combine(DestinationDirectory, Path.GetFileName(FileName)))
ListBox1.Items.Clear()
ListBox1.Items.Add(FileName)
Next FileName
For Each FileName In As String In directory.GetFiles("C:\Users\nha4abt\Desktop\Ahmad_examaning_folder", "*.blf")
File.Delete(Path.GetFileName(FileName))
Next FileName
End Sub
I did that and got the result. It was more like a silly mistake.
Const DestinationDirectory As String = "C:\Users\nha4abt\Desktop\Move_Here"
'Show the parent folder path
Const ParentDirectory As String = "C:\Users\nha4abt\Desktop\Ahmad_examaning_folder"
TextBox1.Text = ParentDirectory
' Show the destination folder path
TextBox2.Text = DestinationDirectory
ListBox1.Items.Clear()
For Each FileName As String In Directory.GetFiles(ParentDirectory, "*.blf")
File.Copy(FileName, Path.Combine(DestinationDirectory, Path.GetFileName(FileName)))
File.Delete(FileName)
ListBox1.Items.Add(FileName)
Next FileName
End Sub
Related
I need to do list of assets that are inside a list of directories. So, the step-by-step is this:
The user selects a Parent Directory which contains all the other
directories with assets and then makes a list with these directories;
Then, I have to access the first directory of the list and make
another list with the assets inside the directory.
The problem is that when I run the code for the first time without the loop, it made the list of directories perfectly. But when I try to run with the loop the Scripting Listener says:
"Error occurred in anonymous codeblock; filename:
E:\MUVA\MaxScript\teste.ms; position: 371; line: 9
-- No "map" function for "\*""
And then I have to restart the 3ds Max and delete the loop for the first step works again. Maybe there's something wrong with my logical that I'm not seeing.
dirPath = getSavePath caption: "SELECT THE PARENT DIRECTORY"
dirList = getDirectories dirPath + "\*"
print ("Directories: " + dirList)
for dir in dirList do(
assetsPath = dir + "\*.max"
assetsList = getFiles assetsPath
print ("List of assets: " + assetsList)
)
And yes, my logical was wrong. I update the code and get ot the result I want.
directoryParent = getSavePath caption: "SELECT THE PARENT DIRECTORY"
dirPath = directoryParent + "\*"
dirList = getDirectories dirPath
print dirList
for dir in dirList do(
assetsPath = dir + "\*.max"
assetsList = getFiles assetsPath
print assetsList
)
I'm exporting data to a text file in qt every time a run a code. With my current code that file is overwritten each time. My question is how can I set the title to be a variable eg pulse_freq, this way new files will be created based on my variable values. I just can't get the syntax right.
Is there a way to put my files in a folder in the same directory as my build files? I need my code to be cross platform and if I use the full path name it's apparently incompatible with any non-windows OS. If I just name the files there'd be too much clutter in the folder. Relevant code is below:
// Export to data file
QString newname = QString::number(variables.nr_pulses);
QString filename = "C:/Users/BIC User/Documents/BIC Placement Documents/QT_data/Data.txt";
QFile file( filename );
You can just use something along lines:
QString s1 = "something";
QString s2 = " else";
QString s3 = s1 + s2;
QString concatenation with overloaded operator+ works like charm.
And about referencing folder you're in, instead of hardcoding its path, use QDir::currentPath()
Thus, your filename creation should look like the following:
QString folder = QDir::currentPath();
QString file = QString::number(variables.nr_pulses); //or whatever else you want it to be
QString extension = ".txt" // or whatever extension you want it to be
QString full_filename = folder + file + extension;
In order not to mess with appending string after the extension, just separate it into another QString and concatenate those 3 elements as above (folder + file + extension).
I want to be able to reference the iMacros folder from my javascrip script in order to write:
retcode = iimPlay(folder + "/macro1.iim");
retcode = iimPlay(folder + "/macro2.iim");
instead of
retcode = iimPlay("test/macro1.iim");
retcode = iimPlay("test/macro2.iim");
I know it is possible in vbs but I don't know if that is the case in javascript.
it works in a similar way with javascript, here is example of the code:
var folder="c:\\data\\"
iimPlay(folder+"1.iim");
this code will run the 1.iim script from c:\data folder
You can make use of inbuilt !FOLDER_DATASOURCE variable to get folder of current javascript macro.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
var folderPath = iimGetExtract();
//Remove 'Datasources' from end of folder path string
folderPath = folderPath.slice(0,-11);
//Append 'Macros' to end of above path
folderPath = folderPath+"Macros\\";
alert(folderPath);
Performing above steps in single command.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Remove 'Datasources' from end of folder path string and append 'Macros'
var folderPath = iimGetExtract().slice(0,-11)+"Macros\\";
alert(folderPath);
Another possible approach is to replace 'Datasources' with 'Macros' in folder path.
//Extract folder path of 'Datasources' folder (located inside 'iMacros' folder)
iimPlayCode("SET !EXTRACT {{!FOLDER_DATASOURCE}}");
//Replace 'Datasources' with 'Macros' in folder path string
var folderPath = iimGetExtract().replace("Datasources","Macros\\");
alert(folderPath);
However it may create problem if folder path contains 'Datasources' anywhere else. You may use any of above methods as per your choice.
Once you get folder path of 'Macros' folder, you can use it like.
retcode = iimPlay(folderPath + "macro1.iim");
I gather a list of files into a QStringList from a Qt GUI. Each of these files is a .txt file, with a corresponding video file in same_folder_as_txt/videos/.
Is there an easy way to manipulate QString objects as file paths? For example, given C:/some/path/foo.txt , I want to retrieve C:/some/path/videos/foo.avi
Given your path as a QString s
info = QFileInfo(s)
// Get the name of the file without the extension
base_name = info.baseName()
// Add a ".avi" extension
video_file = QStringList((base_name, "avi")).join(".")
// Get the directory
dir_name = info.path()
// Construct the path to the video file
video_path = QStringList((dir_name, QString("videos"), video_file).join("/")
You can convert them each to QDir, perform your modifications as a path, and then use absolutePath() to get the QString back.
I need to grab the names of all files in a directory, I am currently using this code:
Dim File As String
File = Dir$(Environ("AppData") & "\*.exe")
Do While Len(File)
MsgBox "Deleting: " & Environ("AppData") & "\" & File
Kill Environ("AppData") & "\" & File
File = Dir$
Loop
This works fine, however it does not display hidden/system files, or files with any attributes other than 'normal', how can I list files no matter their attributes?
I have tried this as well, which has the same outcome:
Kill Environ("AppData") & "\*.*"
The Dir function can take a second parameter for attributes:
File = Dir$(Environ("AppData") & "\*.exe", vbHidden & vbSystem)
You can fin more about the Dir function here.
I pretty much always use the Microsoft Scripting Runtime for file I/O from VB6. It just does more, and it does it better and more easily. One tiny downside is that your VB program is now dependent on the Scripting Runtime DLL (scrrun.dll), which you should add as a reference from within the VB6 IDE.
Here's an example that deletes all files from a folder.
' Note: This code is untested.
Sub Main()
DeleteAllFilesInFolder Environ("App_Data")
End Sub
Sub DeleteAllFilesInFolder(strFolder As String)
Dim fso As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Set fso = New Scripting.FileSystemObject
Set objFolder = fso.GetFolder(strFolder)
For Each objFile in objFolder.Files
objFile.Delete force:=True
Next
End Sub