
Patrick B. answered 10/11/20
Math and computer tutor/teacher
//Compares two absolute pathnames, ignoring the filename
using namespace std;
#include <iostream>
#include <string.h>
int compareFullPathnames( char * pathname1, char * pathname2)
{
int iReturn=-1;
//points at char before null terminator
char * delimPtr1 = pathname1+strlen(pathname1)-1;
char * delimPtr2 = pathname2+strlen(pathname2)-1;
//walks backwards past filename until SLASH
while ((*delimPtr1) != '\\')
{
delimPtr1--;
}
while ((*delimPtr2) != '\\')
{
delimPtr2--;
}
//compares
int N1 = delimPtr1 - pathname1+1;
int N2 = delimPtr2 - pathname2+1;
if (N1==N2) //sizes must be the same
{
int N=N1=N2;
iReturn = strncmp(pathname1,pathname2,N);
}
return(iReturn);
}
int main()
{
//feel free to test with various pathnames; perhaps change the drive letter
char pathname1[] = "C:\\users\\temp\\documents\\filename1.dat";
char pathname2[] = "C:\\users\\temp\\documents\\filename2.dat";
cout << compareFullPathnames(pathname1,pathname2);
}
Henry E.
Can you complete this code while achieving the intended output in my question, please. thank you for your help package samefolder; import java.util.*; import java.text.*; import java.io.*; import java.io.File; public class SameFolder { private static Object f; public static void main(String[] args) { final Formatter sup; try { File file = new File("C:\\Users\\saint\\Desktop"); File f = new File("C:\\Users\\saint\\Desktop"); if(!file.exists() && !f.exists()) { file.createNewFile(); f.createNewFile(); } sup = new Formatter("FileStatistics.java"); System.out.println("File created ^-^!"); System.out.println("Folder created! ^-^"); } catch (IOException e) { System.out.println("IO Exception"); System.out.println("File not created! ;^;"); System.out.println("Folder not created! -_-*"); } } }10/12/20