How to get files ( Through Directory.GetFile() ) on the basis of DateTime
By : Arun Lakshmanan
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further To access all files created yesterday, do something like this in Linq having set up your min/max values desired: Replace CreationTime with LastWriteTime if you want to see file modifications rather than creation: code :
var targetDirectory = "Put your dir here";
var minDate = DateTime.Today.AddDays(-1);
var maxDate = DateTime.Today.AddSeconds(-1);
try
{
var dir = new Directory(targetDirectory);
foreach (var file in dir.GetFiles().Where(f => f.CreationTime >= minDate
&& f.CreationTime <= maxDate))
{
// Do something with file.
Console.WriteLine("File : {0}", file.FullName);
}
}
catch( Exception e )
{
// Handle access exceptions.
}
|
directory.getfile and windows phone 7
By : Hans Wurst
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You are using a string literal and an escape character, you only need one, not both. Try using either code :
Directory.GetFiles(@"c:\Finiti");
Directory.GetFiles("c:\\Finiti");
|
How I can monitor the output files and move/rename in desired directory
By : user3631365
Date : March 29 2020, 07:55 AM
hop of those help? A program generates a text file after every 15 iterations. It overwrites the output.txt (formed at 15th step) with a new output.txt (formed at 30th step), due to using the same name. I can't modify the file name within the program. Can I run some script concurrently with the program on my Ubuntu system that monitors my directory and moves the output.txt file to a desired directory when it is formed or changes the output file name? , I can't modify the file name within the program. code :
std::string uniqueFileName(void)
{
std::stringstream ss;
// vvvvvvvvvv -- unmodifiable-file-name is not changed
ss << "output.txt" << ++fileCount;
uniqueFileName = ss.str();
return(uniqueFileName);
}
|
Find files in a directory containing desired string in Python
By : venkata subba rao ko
Date : March 29 2020, 07:55 AM
I hope this helps you . You are trying to search for string in filename, use open(filename, 'r').read(): code :
import os
user_input = input('What is the name of your directory')
directory = os.listdir(user_input)
searchstring = input('What word are you trying to find?')
for fname in directory:
if os.path.isfile(user_input + os.sep + fname):
# Full path
f = open(user_input + os.sep + fname, 'r')
if searchstring in f.read():
print('found string in file %s' % fname)
else:
print('string not found')
f.close()
|
How to recursively list all files of desired file type in a specified directory?
By : Haneef Ali
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further There are two common methods to get names of all files with a specific file extension found in a directory tree recursively with full path. One common method is using command DIR and the other common method is using command FOR. Example code demonstrating both methods for *.java and *.html files: code :
@echo off
set "JMETALHOME=%CD%"
dir "%JMETALHOME%\jmetal\problems\*.java" "%JMETALHOME%\jmetal\problems\*.html" /B /S >SourcesDir.txt
if exist SourcesFor1.txt del SourcesFor1.txt
for /R "%JMETALHOME%\jmetal\problems" %%I in (*.java *.html) do echo %%I>>SourcesFor1.txt
(for /R "%JMETALHOME%\jmetal\problems" %%I in (*.java *.html) do echo %%I)>SourcesFor2.txt
|